我正在尝试使用Grid.IsSharedSizeScope来排列由GridControl中第一列中某些控件旁边的ItemsControl显示的数据绑定控件.
问题是我不能阻止控制器不断垂直增长.
如何在不设置MaxHeight属性的情况下阻止他们这样做.我已尝试在不同的地方设置VerticalAlignment和VerticalContentAlignment的不同设置,但无法弄明白.
<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>
Run Code Online (Sandbox Code Playgroud)
Gro*_*ile 17
试图在嵌套网格上使用Grid.IsSharedSizeScope不好,将Grid和ItemsControl并排放在另一个有两列的Grid中,很好.
这是我自己的愚蠢的解决方案:
<!-- 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>
Run Code Online (Sandbox Code Playgroud)