How can I make dynamic set columns in grid or what grid analog should I use?
I have a List
, for example List<List<string>> = {{a},{b,c},{d,e},{f,g,h}}
And i need to make from each element a row, and sub-elements should be stretched. like on the picture below. So if there one element, it takes all grid width, if there two sub-elements each takes half of grid's width and so on. I got xaml from here here it is
<Page>
<Page.Resources>
<DataTemplate x:Key="DataTemplate_Level2">
<Button Content="{Binding}" Margin="1,1,1,1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
</DataTemplate>
<DataTemplate x:Key="DataTemplate_Level1">
<ItemsControl ItemsSource="{Binding}" ItemTemplate="{StaticResource DataTemplate_Level2}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DataTemplate>
</Page.Resources>
<Grid>
<ItemsControl ItemsSource="{Binding}" x:Name="lst" ItemTemplate="{StaticResource DataTemplate_Level1}"/>
</Grid>
</Page>
But it can't streach sub-elementslike I need, like this: