Developer
Developer

Reputation: 4321

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?

Upvotes: 3

Views: 913

Answers (2)

Developer
Developer

Reputation: 4321

The best thing was to develop my own Expander.

Upvotes: 0

Hutjepower
Hutjepower

Reputation: 1261

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...

Upvotes: 1

Related Questions