2014-10-09 29 views
0

所以,我有3個用戶控件:SharedSizeGroup到在不同的父控制不同網格

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是在BarVUserControl集合,BarVSectionV作爲兩個擁有。 (SectionV也用作其父控件的收集成員)

問題出在NotationGroupV的中心行高度上,其中SharedSizeGroup="Mid"。我想分享給應用程序中的夥伴NotationGroupV

所以,基本上,我想分享SharedSizeGroup到其他NotationGroupV在不同的父母。

任何人都知道如何公開SharedSizeGroup這種方式?

(請隨意澄清)

謝謝。

P.S.在這個link中,解釋瞭如何在不同的網格中共享它們,但是在相同的xaml中。

+0

儘管我無法確定您的需求是否可行,但我可以確認,只要您將'Grid.IsSharedSizeScope'附加屬性設置爲'True'的父容器控件* Grid's,你已經設置了'SharedSizeGroup's,那麼它*應該*工作。爲了找到答案,只需嘗試一下......你可能已經比自己寫這個問題的時間更快地測試過了。 – Sheridan 2014-10-09 13:14:58

+0

@Sheridan謝謝你的回覆。但是父容器沒有這樣的網格。NotationGroupV擁有這樣的網格,僅由BarV擁有,BarV由父控制擁有。因此,只有NotationGroupV具有SharedSizeScope =「Mid」。我已經嘗試過,只是我不確定「嘗試」你和我的意思是一樣的。你能詳細解釋一下嗎? – 2014-10-09 13:22:40

+0

您應該能夠在*不同網格的任何公共祖先*上設置'Grid.IsSharedSizeScope';它們不必位於同一個文件中,因爲該屬性是在運行時進行評估的。網格不共享一個共同的祖先(父母控制)嗎? – 2014-10-09 13:41:39

回答

2

雖然我不能肯定地確認您的要求將工作,我可以證實,只要你的Grid.IsSharedSizeScope附加屬性設置爲True上的父容器控件的Grid S的兩個已設置高達SharedSizeGroup S表示,那麼它應該工作。爲了找到答案,只需嘗試一下......你可能已經比自己寫這個問題的時間更快地測試過了。

如果此時沒有父容器控件,只需添加一個... ...(把一切都變成它)。 這裏要注意的重要一點是,你只應該設置在每個Grid在一個單親容器控件Grid.IsSharedSizeScopeTrue不能及的。