Reputation: 1027
For example we have a ListBox with a UnidormGrid like a ListBoxPanel.
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}, Path=Items.Count}"></UniformGrid>
<!--<cntr:StackGrid Orientation="Horizontal" Direction="Normal"/>-->
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<Button>1</Button>
<Button>2</Button>
<Button>3</Button>
<Button>4</Button>
</ListBox>
ListBox will give a infinite size to UniformGrid, but there is no any errors. UniformGrid will use only a visible size. How it do that? It will help me in bulding my own panel.
P.S. I know, that i can to disable ScrollView in ListBox and my panel will get a visible size.
Upvotes: 1
Views: 544
Reputation: 5728
As far as I know, the UniformGrid
derives its cell size by the largest child it is displaying. It breaks the content to a new line when either its width or height is exceeded, according to the Orientation
property. By default, it is set to Horizontal
.
Which leads me to your question: why do you think that it has an infinite width? Sure, the ListBox
contains a ScrollViewer
in its default control template, but in my opinion it only provides vertical infinite space for the panel (horizontally, it is constrained to the width of the list box), which allows breaks for the default uniform grid to happen.
If you have any further questions, please feel free to ask.
Upvotes: 1