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 121913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:02:44+00:00 2026-05-11T04:02:44+00:00

If I use a custom panel to layout my ListBoxItems, the ListBox won’t respect

  • 0

If I use a custom panel to layout my ListBoxItems, the ListBox won’t respect their combined Height (it does respect their combined Width though) – even when my ArrangeOverride returns a size that surrounds all the items.

Setting the ListBox’s Height explicitly makes everything work, but I want it to work that out for itself!

Has anyone seen this before?

Thanks

Update: In the example below, the ListBox uses a custom panel that stacks the Articles vertically according to the Row property and returns a size big enough to surround all of them. But unless I set the Height for the ListBox it collapses!

<UserControl x:Class='SilverlightApplication1.Page' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'  xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'  xmlns:local='clr-namespace:SilverlightApplication1'> <UserControl.Resources>     <DataTemplate x:Key='ArticleTemplate'>         <TextBlock Text='{Binding Title}' />     </DataTemplate> </UserControl.Resources> <ListBox Height='200'         Background='AntiqueWhite'         ItemTemplate='{StaticResource ArticleTemplate}'         ItemsSource='{Binding}' VerticalAlignment='Top'         Margin='0,0,0,0'>     <ListBox.ItemsPanel>         <ItemsPanelTemplate>             <local:MyPanel />         </ItemsPanelTemplate>     </ListBox.ItemsPanel> </ListBox> </UserControl> 

Here is the panel:

public class MyPanel : Panel {     protected override Size ArrangeOverride(Size arrangeSize)     {         double width = 0, height = 0;         foreach (UIElement child in this.Children)         {             var article = (Article)((ContentControl)child).DataContext;             var y = child.DesiredSize.Height * article.Row;             var location = new Point(0, y);             var rect = new Rect(location, child.DesiredSize);             child.Arrange(rect);             width = Math.Max(width, child.DesiredSize.Width);             height = Math.Max(height, y + child.DesiredSize.Height);         }          return new Size(width, height);     }      protected override Size MeasureOverride(Size availableSize)     {         foreach (UIElement child in this.Children)         {             if (child != null)             {                 child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));             }         }          return new Size();     } } 

And the domain class:

public class Article {     private readonly int row;     private readonly string title;      public Article(string title, int row)     {         this.title = title;         this.row = row;     }      public int Row { get { return this.row; } }      public string Title { get { return this.title; } } } 
  • 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. 2026-05-11T04:02:45+00:00Added an answer on May 11, 2026 at 4:02 am

    I was not able to reproduce the problem that you described. Could you provide some example code/xaml so that I can take a look?

    UPDATE:

    I believe the problem here is that you are returning (0,0) as the Panel’s DesiredSize from MeasureOverride. You probably want to do something like:

        protected override Size MeasureOverride(Size availableSize)     {         double width = 0;         double height = 0;         foreach (UIElement child in this.Children)         {             if (child != null)             {                 child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));                 width = Math.Max(width, child.DesiredSize.Width);                 height = Math.Max(height, child.DesiredSize.Height);             }         }          return new Size(width, height);     } 

    The actual sizing logic is likely to be different depending on your requirements.

    What is happening in your code is that by returning (0,0) from MeasureOverride, your Panel is essentially ‘asking’ its parent for this amount of space to be reserved for it. So when it comes to the Arrange phase of the layout cycle the finalSize passed to ArrangeOverride is very small (0 in at least one dimension). You can verify this by setting a breakpoint in ArrangeOverride and then examining the finalSize parameter. To get your code to work correctly with the layout system, you need to return from MeasureOverride the minimum amount of space that your Panel needs to contain its children.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use a temp directory that will be unique to this build.
(please excuse that I didn't use aliases). I would like my query output to
My question is about memory use and objects in actionscript 2. If I have
I make a distributed embedded application that will make use of several micro-controllers. The
I need to develop a file indexing application in python and wanted to know
I need to solve the following question which i can't get to work by
I am learning on my own about writing an interpreter for a programming language,
I have a new web app that is packaged as a WAR as part
We manage a site for a medical charity. They have a number of links
I've found several jQuery syntaxes for nullifying the enter on a form. First one:

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.