我正在尝试使用ItemsControl
在另一个网格中嵌入多个网格,并让所有子网格共享相同的行高:
<Grid>
<ItemsControl ItemsSource="{Binding ControlItems}">
<ItemsControl.ItemsPanel>
<CustomPanel></CustomPanel>
</ItemsControl.ItemsPanel>
<ItemsControl.DataTemplate>
<CustomControl/>
</ItemsControl.DataTemplate>
</ItemsControl>
</Grid>
其中CustomControl实际上是一个这样的自定义网格:
<Grid>
<Grid.RowDefinitions>
<RowDefinition SharedSizeGroup="CustomControlGroup" />
<RowDefinition SharedSizeGroup="CustomControlGroup" />
<Grid.RowDefinitions>
</Grid>
然而,子网格中的行不共享相同的大小?
答案 0 :(得分:3)
根据这个article。您必须将父控件中的IsSharedSizeScope
属性设置为True
。所以可能看起来应该更像:
<ItemsControl Grid.IsSharedSizeScope="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition SharedSizeGroup="CustomControlGroup" />
<RowDefinition SharedSizeGroup="CustomControlGroup" />
<Grid.RowDefinitions>
</Grid>
</ItemsControl>
Here是MSDN的另一个例子。恕我直言,第一篇文章更容易理解。