Problem with WPF layout using Grid.IsSharedSizeScope and ItemsControl.ItemTemplate

I'm trying to use Grid.IsSharedSizeScope to align the data controls displayed by the ItemsControl next to some edges in the first column of the grid.

The problem is that I cannot prevent the controls from constantly growing vertically.

How can I stop them if I don't set the MaxHeight properties. I tried different VerticalAlignment and VerticalContentAlignment settings in different places, but I can not understand.

<Grid Grid.IsSharedSizeScope="True" > <Grid.RowDefinitions> <RowDefinition SharedSizeGroup="RowOne" /> <RowDefinition SharedSizeGroup="RowTwo" /> <RowDefinition SharedSizeGroup="RowThree" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <SomeControl Grid.Row="0" Grid.Column="0" /> <SomeControl Grid.Row="1" Grid.Column="0" /> <ItemsControl Grid.Row="0" Grid.Column="1" Grid.RowSpan="3" ItemsSource="{Binding Path=SomeSource}" ItemsPanel="{StaticResource MyHorizontalStackPanel}" > <ItemsControl.ItemTemplate> <DataTemplate> <Grid> <Grid.RowDefinitions> <RowDefinition SharedSizeGroup="RowOne" /> <RowDefinition SharedSizeGroup="RowTwo" /> <RowDefinition SharedSizeGroup="RowThree" /> </Grid.RowDefinitions> <SomeControl Grid.Row="0" /> <SomeControl Grid.Row="1" /> <SomeControl Grid.Row="2" /> </Grid> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </Grid> 
+4
source share
1 answer

Trying to use Grid.IsSharedSizeScope on nested meshes is bad, putting the Grid and ItemsControl side by side inside another Grid with two columns, fine.

Here is my own solution to my own stupidity:

 <!-- outer grid (could be a stack panel) --> <Grid Grid.IsSharedSizeScope="True"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <!-- header --> <Grid Grid.Column="0" Margin="0,10,10,0"> <Grid.RowDefinitions> <RowDefinition SharedSizeGroup="RowOne" /> <RowDefinition SharedSizeGroup="RowTwo" /> <RowDefinition SharedSizeGroup="RowThree" /> </Grid.RowDefinitions> <SomeControl Grid.Row="0" Grid.Column="0" /> <SomeControl Grid.Row="1" Grid.Column="0" /> </Grid> <!-- rows --> <ItemsControl Grid.Column="1" ItemsSource="{Binding Path=SomeSource}"> <ItemsControl.ItemTemplate> <DataTemplate> <Grid> <Grid.RowDefinitions> <RowDefinition SharedSizeGroup="RowOne" Height="Auto" /> <RowDefinition SharedSizeGroup="RowTwo" Height="Auto" /> <RowDefinition SharedSizeGroup="RowThree" Height="Auto" /> </Grid.RowDefinitions> <!-- define your row here --> </Grid> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </Grid> 
+15
source

Source: https://habr.com/ru/post/1339679/


All Articles