具有ItemsControl嵌入式网格的SharedGridSize组 [英] SharedGridSize group with ItemsControl embedded Grids

查看:89
本文介绍了具有ItemsControl嵌入式网格的SharedGridSize组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to embed multiple grids within another grid using an ItemsControl and have all the child grids share the same row heights:

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

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

Where CustomControl is actually a customized Grid something like this:

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

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

However the rows in the child grids do not share the same size?

推荐答案

根据此文章.您必须将父控件中的IsSharedSizeScope属性设置为True.因此,它看起来应该更像:

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>

此处是MSDN中的另一个示例.恕我直言,第一篇文章更容易理解.

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

这篇关于具有ItemsControl嵌入式网格的SharedGridSize组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆