Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8609029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:46:20+00:00 2026-06-12T03:46:20+00:00

In my Metro application, I have a data source containing a certain number of

  • 0

In my Metro application, I have a data source containing a certain number of items (say 25). I have a ListView that presents those items. My problem is that the ListView have a size that allows it to display, say, 6.5 items, so that the last item it displays is cut in half. If the resolution changes, it might display 4 items, or 8.2 items, or whatever. What I’d like is that the ListView shows exactly the number of items that fits in the height of the control, instead of clipping the last item.

Right now, I see two possible half-solutions, none of which is optimal:

  1. Set the height of the ListView to a fixed height that is a multiple of the item size. This does not scale with changes in resolution.

  2. Limit the number of items in the data source. This does not scale either.

So my question is, how can I get the ListView to only display complete items (items where all edges are inside the viewport/listview), and hide the rest?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:46:21+00:00Added an answer on June 12, 2026 at 3:46 am

    My final solution was to combine the suggestions of @NovitchiS and @JesuX.

    I created a stack panel override, and listened to the LayoutUpdated event. My final solution:

    class HeightLimitedStackPanel : StackPanel
    {
        public HeightLimitedStackPanel() : base()
        {
            this.LayoutUpdated += OnLayoutUpdated;
        }
    
        double GetSizeOfVisibleChildren(double parentHeight)
        {
            double currentSize = 0;
            bool hasBreaked = false;
            for (int i = 0; i < Children.Count; i++)
            {
                var child = Children[i];
                if (currentSize + child.DesiredSize.Height > parentHeight)
                {
                    hasBreaked = true;
                    break;
                }
                currentSize += child.DesiredSize.Height;
            }
            if (hasBreaked) return currentSize;
    
            return parentHeight;
        }
    
        double ParentHeight
        {
            get 
            {
                ItemsPresenter parent = VisualTreeHelper.GetParent(this) as ItemsPresenter;
                if (parent == null)
                    return 0;
    
                return parent.ActualHeight;
            }
        }
    
        double previousHeight = 0;
        int previousChildCount = 0;
        protected void OnLayoutUpdated(object sender, object e)
        {
            double height = ParentHeight;
            if (height == previousHeight && previousChildCount == Children.Count) return;
            previousHeight = height;
            previousChildCount = Children.Count;
    
            this.Height = GetSizeOfVisibleChildren(height);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created metro style Grid Application which preview data that i get it
Using Netbeans 6.8 and metro 2.0 I have written a simple application that makes
I have a NSIS installer that installs my non-Metro application on Windows 8. After
I want to create a webapi that serves data to my windows8 metro application
I have a regular Windows API ( not metro ) application that I would
I have a Windows 8 Metro application created from the Grid Application template. I
I have used FlipView from Metro Applications and that's what I'm trying to looking
I find that, Windows 8 will be highly HTML5 + Javascript based Metro Application
We have an MTOM-enabled web service that is published with Grails and the Metro
I am trying to write a metro style application to read data from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.