所以,我有 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>
...
如你所想,NotationGroupV是BarV中UserControl的集合,BarV归属于SectionV 作为两个。 (SectionV 也用作其父控件的集合成员)
问题出在 NotationGroupV 的中心行高上,它具有 SharedSizeGroup="Mid"。我想将它分享给应用程序中的其他 NotationGroupV。
所以,基本上,我想将 SharedSizeGroup 共享给不同父级中的其他 NotationGroupV。
有人知道如何以这种方式公开 SharedSizeGroup 吗?
(请问任何澄清)
谢谢。
附言在这个link ,它解释了如何在不同的网格中共享它们,但在同一个 xaml 中。
请您参考如下方法:
虽然我无法确定您的要求是否有效,但我可以确认,只要您将 Grid.IsSharedSizeScope 附加属性设置为 True您为其设置了 SharedSizeGroup 的 Grid 的 both 的父容器控件,那么它应该工作.要确定地找出答案,只需尝试一下......您自己测试它的速度可能比您写这个问题所花的时间还快。
如果此时没有父容器控件,就加一个....(把所有东西都放进去)。 此处需要注意的重要一点是,您只应在单个父容器控件上将 Grid.IsSharedSizeScope 设置为 True,而不是在每个 Grid.
