【问题标题】:How to set HubSection Header Style如何设置 HubSection 标题样式
【发布时间】:2015-04-23 01:24:31
【问题描述】:
我想更改 HubSection Header 的字体系列、字体大小和前景色。
类似这样的:
<Style TargetType="HubSection" x:Key="HubSection">
<Setter Property="Header">
<Setter.Value>
<Setter Property="FontSize" Value="100"></Setter>
<Setter Property="Foreground" Value="Yellow"></Setter>
</Setter.Value>
</Setter>
</Style>
<HubSection Width="500" Header="Section Name" Style="{StaticResource HubSection}">
我该怎么做?
【问题讨论】:
标签:
xaml
windows-phone-7
windows-phone-8
windows-8.1
【解决方案1】:
您要更改的属性不是Header,而是HeaderTemplate。这是我的工作示例:
<Style TargetType="HubSection">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}"
FontSize="100"
Foreground="Yellow"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
如果您想将此样式应用于应用中的所有Hub 控件,只需删除Key 并将其放入Resources 中的App.xaml 文件中。
【解决方案2】:
如果您不想覆盖标题模板,您可以覆盖默认主题资源:
<FontWeight x:Key="HubSectionHeaderThemeFontWeight">SemiLight</FontWeight>
<x:Double x:Key="HubSectionHeaderThemeFontSize">26.667</x:Double>
很遗憾,FontFamily 和 Foreground 没有特殊资源。模板使用 Button 的默认值。因此,您将影响整个应用程序。但在很多情况下,这正是您想要的,对吧?
<FontFamily x:Key="ContentControlThemeFontFamily">Segoe UI</FontFamily>
<SolidColorBrush x:Key="ButtonForegroundThemeBrush" Color="Red" />