2015-10-13 31 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> 
相关问题