我想为Hub创建模板,因为我在Header中需要复杂的StackPanel
,但我无法弄清楚如何去做。首先,我想检查TextBlock
控件,所以我写了三个样本样式:
<Style x:Key="HubSectionStyle" TargetType="HubSection">
<Setter Property="Header" Value="With Style1">
</Setter>
</Style>
<Style x:Key="HubSectionStyle2" TargetType="HubSection">
<Setter Property="Header">
<Setter.Value>
<DataTemplate>
<TextBlock>With Style2</TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="HubSectionStyle3" TargetType="HubSection">
<Setter Property="Header">
<Setter.Value>
<ControlTemplate>
<TextBlock>With Style3</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
并试着这样:
<HubSection>
<HubSection.Header>
<TextBlock>Without Style</TextBlock>
</HubSection.Header>
</HubSection>
<HubSection Style="{StaticResource HubSectionStyle}">
</HubSection>
<HubSection Style="{StaticResource HubSectionStyle2}">
</HubSection>
<HubSection Style="{StaticResource HubSectionStyle3}">
</HubSection>
因此,我有四列包含以下标题:
没有风格, 使用Style1, Windows.UI.Xaml.DataTemplate, Windows.UI.Xaml.ControlTemplate
答案 0 :(得分:5)
使用HeaderTemplate
为标题定义模板..
<Style x:Key="HubSectionStyle2" TargetType="HubSection">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock>With Style2</TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
获取有关HeaderTemplate
的更多详细信息,您可以here..