2

我正在尝试使用 an 在另一个网格中嵌入多个网格,ItemsControl并让所有子网格共享相同的行高:

<Grid>
    <ItemsControl ItemsSource="{Binding ControlItems}">
        <ItemsControl.ItemsPanel>
            <CustomPanel></CustomPanel>
        </ItemsControl.ItemsPanel>
        <ItemsControl.DataTemplate>
            <CustomControl/>
        </ItemsControl.DataTemplate>
    </ItemsControl>
</Grid>

CustomControl 实际上是一个自定义的 Grid ,如下所示:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition SharedSizeGroup="CustomControlGroup" />
        <RowDefinition SharedSizeGroup="CustomControlGroup" />
    <Grid.RowDefinitions>
</Grid>

但是子网格中的行不共享相同的大小?

4

1 回答 1

3

Well according to this article. You must set the IsSharedSizeScope property in a parent control to True. So probably it should look more like:

<ItemsControl Grid.IsSharedSizeScope="True">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition SharedSizeGroup="CustomControlGroup" />
            <RowDefinition SharedSizeGroup="CustomControlGroup" />
        <Grid.RowDefinitions>
    </Grid>
</ItemsControl>

Here is another example from the MSDN. IMHO, the first article is more understandable.

于 2013-05-15T07:44:54.280 回答