2015-10-13 78 views
3

我目前有一個帶有3個網格的透視和具有相同網格的ScrollViewer。正如任何軟件工程師可以做的那樣,我只想要一次代碼,而不是兩次。所以我的問題是:我該怎麼做?如何在UWP中重用XAML中的網格Windows 10

+2

使用用戶控件 – Akansha

+0

一個例子,將不勝感激,因爲我無法找到一個合適的。 – Teysz

+0

請找到鏈接http://www.codeproject.com/Articles/32825/How-to-Creating-a-WPF-User-Control-using-it-in-aW – Akansha

回答

4

得到了解決:我把我的三個網格在三個獨立的DataTemplates並參照這些模板從樞軸內,並從ScrollViewer中內:

<Page.Resources> 
    ... 
    <DataTemplate x:Key="JustANormalGridNr1"> 
     <Grid /> 
    </DataTemplate> 
    <DataTemplate x:Key="JustANormalGridNr2"> 
     <Grid /> 
    </DataTemplate> 
    <DataTemplate x:Key="JustANormalGridNr3"> 
     <Grid /> 
    </DataTemplate> 
</Page.Resources> 

<Grid x:Name="MasterGrid"> 
    <Pivot> 
     <Pivot.Items> 
     <PivotItem> 
      ... 
      <Grid> 
       <ContentControl ContentTemplate="{StaticResource JustANormalGridNr1}" /><!--instead of the grid, a reference to it --> 
      </Grid> 
     </PivotItem> 
     <PivotItem> 
      ... 
      <Grid> 
       <ContentControl ContentTemplate="{StaticResource JustANormalGridNr2}" /><!--instead of the grid, a reference to it --> 
      </Grid> 
     </PivotItem> 
     <PivotItem> 
      ... 
      <Grid> 
       <ContentControl ContentTemplate="{StaticResource JustANormalGridNr3}" /><!--instead of the grid, a reference to it --> 
      </Grid> 
     </PivotItem> 
     </Pivot.Items> 
    </Pivot> 

    <ScrollViewer> 
     <Grid> 
     <Grid> 
      ... 
      <Grid Grid.Column="0"> 
       ... 
       <ContentControl Grid.Row="1" ContentTemplate="{StaticResource JustANormalGridNr1}" /><!-- Instead of the grid, a reference to it --> 
      </Grid> 
      <Grid Grid.Column="1"> 
       ... 
       <ContentControl Grid.Row="1" ContentTemplate="{StaticResource JustANormalGridNr2}" /><!-- Instead of the grid, a reference to it --> 
      </Grid> 
      <Grid Grid.Column="2"> 
       ... 
       <ContentControl Grid.Row="1" ContentTemplate="{StaticResource JustANormalGridNr3}" /><!-- Instead of the grid, a reference to it --> 
      </Grid> 
     </Grid> 
     </Grid> 
    </ScrollViewer> 
</Grid> 
相關問題