0
下面的XAML工作確定:使用Pivot.ItemTemplate避免複製
<Page ...
<Page.Resources>
<SolidColorBrush x:Key="brushHeaderBkgr" Color="Blue" />
<SolidColorBrush x:Key="brushContentBorder" Color="Aquamarine" />
<SolidColorBrush x:Key="brushContentBkgr" Color="Blue" />
<SolidColorBrush x:Key="brushContentList" Color="Red" />
<Style TargetType="Border" x:Key="ContentFrame">
<Setter Property="BorderBrush" Value="{StaticResource brushContentBorder}" />
<Setter Property="BorderThickness" Value="6" />
<Setter Property="Padding" Value="6" />
<Setter Property="Background" Value="{StaticResource brushContentBkgr}" />
</Style>
<Style TargetType="ListView" x:Key="ContentList" >
<Setter Property="Background" Value="{StaticResource brushContentList}" />
</Style>
</Page.Resources>
<Grid>
<Pivot Title="Whatever" Margin="10">
<PivotItem Header="Header1" >
<Border Style="{StaticResource ContentFrame}">
<ListView x:Name="Content" Style="{StaticResource ContentList}" />
</Border>
</PivotItem>
<PivotItem Header="Header2" >
<Border Style="{StaticResource ContentFrame}">
<ListView x:Name="Content" Style="{StaticResource ContentList}" />
</Border>
<PivotItem Header="Header3" >
<Border Style="{StaticResource ContentFrame}">
<ListView x:Name="Content" Style="{StaticResource ContentList}" />
</Border>
</Pivot>
</Grid>
</Page>
由於所有的商品頁面,具有相同的結構,我想用Pivot.ItemTemplate以避免複製。這裏是修改的XAML:
<Page ...
<Page.Resources>
<SolidColorBrush x:Key="brushHeaderBkgr" Color="Blue" />
<SolidColorBrush x:Key="brushContentBorder" Color="Aquamarine" />
<SolidColorBrush x:Key="brushContentBkgr" Color="Blue" />
<SolidColorBrush x:Key="brushContentList" Color="Red" />
<Style TargetType="Border" x:Key="ContentFrame">
<Setter Property="BorderBrush" Value="{StaticResource brushContentBorder}" />
<Setter Property="BorderThickness" Value="6" />
<Setter Property="Padding" Value="6" />
<Setter Property="Background" Value="{StaticResource brushContentBkgr}" />
</Style>
<Style TargetType="ListView" x:Key="ContentList" >
<Setter Property="Background" Value="{StaticResource brushContentList}" />
</Style>
</Page.Resources>
<Grid>
<Pivot Title="Whatever" Margin="10">
<Pivot.ItemTemplate>
<DataTemplate>
<Border Style="{StaticResource ContentFrame}">
<ListView x:Name="Content" Style="{StaticResource ContentList}" />
</Border>
</DataTemplate>
</Pivot.ItemTemplate>
<PivotItem Header="Header1" />
<PivotItem Header="Header2" />
<PivotItem Header="Header3" />
</Grid>
</Page>
但是,這不起作用,項目不會出現。爲什麼?