Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StackPanel cuts off elements

I have xaml custom listbox item, which height is 165px

I'm fillin StackPanel with those items:

StackPanel list = new StackPanel();
foreach (Course course in Semestris.Courses)
{
    TI.Course.Text = course.Name;
    list.Children.Add(TI);
}
Color color = ConvertStringToColor("#FF838383");
Brush brush = new SolidColorBrush(color);
list.Background = brush;
list.Height = list.Children.Count*165; //make size of stack panel just as to display all elements

And add color to find a bug.

This stack panel is being placed inside Expander StackPanel:

Expander.Expander a = new Expander.Expander();
a.IsExpanded = false;
a.Content = list;
a.HeaderContent = Semestris.Name;

Expander control has every row set to auto which means it will aply sizes of children.

And the last step to place all Expander into 1 stack:

Stack.Children.Add(a);

And my problem is that:

All colapsed expanders work fine:

Collapsed

When items are not many, all works fine:

1 item

But when items count is over 30 items it does this:

Cutted off

Where is the problem?

like image 927
Cheese Avatar asked Nov 30 '25 21:11

Cheese


1 Answers

Looks like you have an issue with the height property somewhere in your stackpanel or expander (regardless of how many items you have in your list or expander). But just like Chris W. I would like to suggest to put all UI related statements more in XAML then in the code behind.

When you do so, use more Grids with rowdefinitions set to auto or * as height to indicate a necessary or all remaining height and use binding for data. Might be some rework, but from there it is more easy to see what is really happening...

like image 74
Hutjepower Avatar answered Dec 02 '25 13:12

Hutjepower



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!