SharedSizeGroup到不同父控件中的不同Grid

时间:2014-10-09 12:56:49

标签: c# wpf xaml user-controls sharedsizegroup

所以,我有3个用户控件:

1。 SectionV.xaml

<UserControl x:Class="NumberedMusicalScoresWriter.V.SectionV"...>
...
    <Grid Background="{Binding BackgroundColor, Mode=OneWay}" Grid.IsSharedSizeScope="True">
        ...
        <V:BarV Grid.Column="0" Grid.Row="0" DataContext="{Binding GClefBarVM, Mode=OneWay}"/>
        <V:BarV Grid.Column="0" Grid.Row="2" DataContext="{Binding FClefBarVM, Mode=OneWay}"/>
    </Grid>
...

2。 BarV.xaml

<UserControl x:Class="NumberedMusicalScoresWriter.V.BarV"...>
...
    <Grid Background="{Binding BackgroundColor, Mode=OneWay}">
        ...
        <ItemsControl Grid.Column="0" Grid.Row="0"
                      ItemsSource="{Binding NotationGroupVMs, Mode=OneWay}">
            ...
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <V:NotationGroupV/>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
...

第3。 NotationGroupV.xaml

<UserControl x:Class="NumberedMusicalScoresWriter.V.NotationGroupV"...>
...
    <Grid Background="{Binding BackgroundColor, Mode=OneWay}">
        ...
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto" SharedSizeGroup="Mid"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        ...
    </Grid>
...

根据您的想法,NotationGroupVUserControlBarV的集合,而BarVSectionV所拥有的两个。 (SectionV也用作其父控件的集合成员)

问题出在NotationGroupV的中心行高,其中SharedSizeGroup="Mid"。我想在应用中与同事NotationGroupV分享。

所以,基本上,我想将SharedSizeGroup分享给不同父母的其他NotationGroupV

任何人都知道如何以这种方式公开SharedSizeGroup吗?

(请提出任何要澄清的内容)

谢谢。

P.S。在这个link中,它解释了如何在不同的网格中共享它们,但是在相同的xaml中。

1 个答案:

答案 0 :(得分:2)

虽然我无法确认您的要求是否有效,但只要您在Grid.IsSharedSizeScope附加属性设置为True,我就可以确认>您为Grid设置的SharedSizeGroup的,然后 应该工作。要确定一下,试一试......你本可以比你写这个问题的时间更快地测试它。

如果此时没有父容器控件,只需添加一个....(将所有内容放入其中)。 这里要注意的重要一点是,您只应该在单个父容器控件上设置Grid.IsSharedSizeScopeTrue,而不是在每个Grid上设置。