c# windows phone 8.1 更改默认控件颜色
c# windows phone 8.1 change default controls color
在我的 wp 应用程序中,我希望所有控件的颜色都是黑色;对于文本块和文本框,我只是在字典中声明了这样的样式:
<Style x:Key="TextColor" TargetType="TextBlock">
<Setter Property="Foreground" Value="Black"/>
</Style>
我还有一些时间选择器控件和一个复选框,我无法在其中分别修改 header 和框的颜色。这就是我所做的:
CheckBox VerticalAlignment="Top"
HorizontalAlignment="Right"
Margin="0,110,0,0"
x:Name="dayOffBox"
Content="Day off?" Checked="DayOff_Checked"
Foreground="Black"/>
这样,checkbox内容的文字"Day off?"是黑色的,但是box还是白色的
Header 时间选择器也一样。我必须更改应用程序文本的默认颜色吗?我该怎么做?
您是否尝试过覆盖默认画笔?
就像在 App.xaml 个合并词典中添加条目:
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="ApplicationForegroundThemeBrush" Color="Magenta" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
您可以通过编辑控件的默认样式来编辑任何控件样式。在 CheckBox
的情况下,它是以下内容:
<Style TargetType="CheckBox">
<Setter Property="Background" Value="{ThemeResource CheckBoxBackgroundThemeBrush}" />
<Setter Property="BorderBrush" Value="{ThemeResource CheckBoxBorderThemeBrush}" />
<Setter Property="BorderThickness" Value="{ThemeResource PhoneBorderThickness}" />
<Setter Property="FontSize" Value="{ThemeResource TextStyleLargeFontSize}" />
<Setter Property="FontFamily" Value="{ThemeResource PhoneFontFamilyNormal}" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Top" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Padding" Value="{ThemeResource CheckBoxAndRadioButtonTextPaddingThickness}" />
<Setter Property="MinWidth" Value="{ThemeResource CheckBoxAndRadioButtonMinWidthSize}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="CheckBox">
<Grid Background="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver" />
<VisualState x:Name="PointerOver" />
<VisualState x:Name="Pressed">
<Storyboard>
<PointerDownThemeAnimation Storyboard.TargetName="Grid" />
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckBackground" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CheckBoxPressedBackgroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckGlyph" Storyboard.TargetProperty="Fill">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CheckBoxPressedForegroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="NormalRectangle" Storyboard.TargetProperty="Fill">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CheckBoxPressedBackgroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckBackground" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CheckBoxDisabledBorderThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckGlyph" Storyboard.TargetProperty="Fill">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CheckBoxDisabledForegroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="NormalRectangle" Storyboard.TargetProperty="Fill">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CheckBoxDisabledBackgroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CheckBoxDisabledForegroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualStateGroup.Transitions>
<VisualTransition From="Pressed" To="PointerOver">
<Storyboard>
<PointerUpThemeAnimation Storyboard.TargetName="Grid" />
</Storyboard>
</VisualTransition>
<VisualTransition From="PointerOver" To="Normal">
<Storyboard>
<PointerUpThemeAnimation Storyboard.TargetName="Grid" />
</Storyboard>
</VisualTransition>
<VisualTransition From="Pressed" To="Normal">
<Storyboard>
<PointerUpThemeAnimation Storyboard.TargetName="Grid" />
</Storyboard>
</VisualTransition>
</VisualStateGroup.Transitions>
</VisualStateGroup>
<VisualStateGroup x:Name="CheckStates">
<VisualState x:Name="Checked">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckGlyph" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Unchecked" />
<VisualState x:Name="Indeterminate">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="NormalRectangle" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid x:Name="Grid" Margin="{ThemeResource PhoneTouchTargetLargeOverhang}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25.5" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" VerticalAlignment="Top">
<Border x:Name="CheckBackground"
IsHitTestVisible="False"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Height="25.5"
Width="25.5" />
<Rectangle x:Name="NormalRectangle"
IsHitTestVisible="False"
Width="13"
Height="13"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Fill="{ThemeResource CheckBoxBackgroundThemeBrush}"
Visibility="Collapsed" />
<Path x:Name="CheckGlyph"
IsHitTestVisible="False"
Visibility="Collapsed"
Width="18.5"
Height="17"
Stretch="Fill"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Fill="{ThemeResource CheckBoxForegroundThemeBrush}"
Data="M0,123 L39,93 L124,164 L256,18 L295,49 L124,240 z"
StrokeLineJoin="Round"
StrokeThickness="2.5"
FlowDirection="LeftToRight" />
</Grid>
<ContentPresenter x:Name="ContentPresenter"
Grid.Column="1" Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Foreground="{TemplateBinding Foreground}"
FontFamily="{ThemeResource PhoneFontFamilyNormal}"
FontSize="{ThemeResource TextStyleLargeFontSize}"
FontWeight="Normal"
AutomationProperties.AccessibilityView="Raw" />
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
要将颜色更改为黑色,您需要将 CheckGlyph
Path
元素上的 Fill
属性 从 CheckBoxForegroundThemeBrush
更改为另一个值.或者您可以完全更改 CheckBox
控件的视觉外观。你可以自己做实验。
另一种方法是通过将以下任何资源添加到您的 App.xaml
来覆盖它们:
<SolidColorBrush x:Key="CheckBoxBorderThemeBrush" Color="Black" />
<SolidColorBrush x:Key="CheckBoxContentDisabledForegroundThemeBrush" />
<SolidColorBrush x:Key="CheckBoxContentForegroundThemeBrush" />
<SolidColorBrush x:Key="CheckBoxDisabledBorderThemeBrush" />
<SolidColorBrush x:Key="CheckBoxDisabledForegroundThemeBrush" />
<SolidColorBrush x:Key="CheckBoxForegroundThemeBrush" />
<SolidColorBrush x:Key="CheckBoxPointerOverBackgroundThemeBrush" />
<SolidColorBrush x:Key="CheckBoxPointerOverForegroundThemeBrush" />
<SolidColorBrush x:Key="CheckBoxPointerOverBorderThemeBrush" />
<SolidColorBrush x:Key="CheckBoxPressedBackgroundThemeBrush" />
<SolidColorBrush x:Key="CheckBoxPressedBorderThemeBrush" />
<SolidColorBrush x:Key="CheckBoxPressedForegroundThemeBrush" />
他们将更改的内容的含义是自我描述的,并且他们需要具有完全相同的名称。
您的 App.xaml
可能看起来像这样:
<Application
x:Class="MyApp"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
RequestedTheme="Light">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<!-- Overriden theme resources -->
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="CheckBoxBorderThemeBrush" Color="Black" />
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="CheckBoxBorderThemeBrush" Color="White" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<ResourceDictionary.MergedDictionaries>
<!-- Other resources -->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
至于 TimePicker
默认样式如下:
<Style TargetType="TimePicker">
<Setter Property="FontFamily" Value="{ThemeResource PhoneFontFamilyNormal}" />
<Setter Property="FontSize" Value="{ThemeResource ContentControlFontSize}" />
<Setter Property="Foreground" Value="{ThemeResource TimePickerForegroundThemeBrush}" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TimePicker">
<StackPanel Margin="{TemplateBinding Padding}" x:Name="LayoutRoot">
<ContentPresenter x:Name="HeaderContentPresenter" Style="{StaticResource HeaderContentPresenterStyle}" Margin="0,0,0,-3"
Content="{TemplateBinding Header}" ContentTemplate="{TemplateBinding HeaderTemplate}" />
<Button x:Name="FlyoutButton"
Foreground="{TemplateBinding Foreground}"
BorderBrush="{TemplateBinding Foreground}"
BorderThickness="2.5"
Padding="6.5,0,0,3"
IsEnabled="{TemplateBinding IsEnabled}"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
所以 TimePicker
header 颜色的解决方案是创建一个新的 TimePicker
样式,并设置 HeaderContentPresenter
元素的 Foreground
,或者您可以只更改 TimePicker
的 HeaderTemplate
而无需创建新样式:
<TimePicker Foreground="Black">
<TimePicker.Header>
<TextBlock Text="Header Text Example" Foreground="Black">
</TimePicker.Header>
</TimePicker>
或
<TimePicker Foreground="Black" Header="Header Text Example">
<TimePicker.HeaderTemplate>
<TextBlock Text="{Binding}" Foreground="Black">
</TimePicker.Header>
</TimePicker>
在我的 wp 应用程序中,我希望所有控件的颜色都是黑色;对于文本块和文本框,我只是在字典中声明了这样的样式:
<Style x:Key="TextColor" TargetType="TextBlock">
<Setter Property="Foreground" Value="Black"/>
</Style>
我还有一些时间选择器控件和一个复选框,我无法在其中分别修改 header 和框的颜色。这就是我所做的:
CheckBox VerticalAlignment="Top"
HorizontalAlignment="Right"
Margin="0,110,0,0"
x:Name="dayOffBox"
Content="Day off?" Checked="DayOff_Checked"
Foreground="Black"/>
这样,checkbox内容的文字"Day off?"是黑色的,但是box还是白色的
Header 时间选择器也一样。我必须更改应用程序文本的默认颜色吗?我该怎么做?
您是否尝试过覆盖默认画笔? 就像在 App.xaml 个合并词典中添加条目:
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="ApplicationForegroundThemeBrush" Color="Magenta" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
您可以通过编辑控件的默认样式来编辑任何控件样式。在 CheckBox
的情况下,它是以下内容:
<Style TargetType="CheckBox">
<Setter Property="Background" Value="{ThemeResource CheckBoxBackgroundThemeBrush}" />
<Setter Property="BorderBrush" Value="{ThemeResource CheckBoxBorderThemeBrush}" />
<Setter Property="BorderThickness" Value="{ThemeResource PhoneBorderThickness}" />
<Setter Property="FontSize" Value="{ThemeResource TextStyleLargeFontSize}" />
<Setter Property="FontFamily" Value="{ThemeResource PhoneFontFamilyNormal}" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Top" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Padding" Value="{ThemeResource CheckBoxAndRadioButtonTextPaddingThickness}" />
<Setter Property="MinWidth" Value="{ThemeResource CheckBoxAndRadioButtonMinWidthSize}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="CheckBox">
<Grid Background="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver" />
<VisualState x:Name="PointerOver" />
<VisualState x:Name="Pressed">
<Storyboard>
<PointerDownThemeAnimation Storyboard.TargetName="Grid" />
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckBackground" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CheckBoxPressedBackgroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckGlyph" Storyboard.TargetProperty="Fill">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CheckBoxPressedForegroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="NormalRectangle" Storyboard.TargetProperty="Fill">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CheckBoxPressedBackgroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckBackground" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CheckBoxDisabledBorderThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckGlyph" Storyboard.TargetProperty="Fill">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CheckBoxDisabledForegroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="NormalRectangle" Storyboard.TargetProperty="Fill">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CheckBoxDisabledBackgroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CheckBoxDisabledForegroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualStateGroup.Transitions>
<VisualTransition From="Pressed" To="PointerOver">
<Storyboard>
<PointerUpThemeAnimation Storyboard.TargetName="Grid" />
</Storyboard>
</VisualTransition>
<VisualTransition From="PointerOver" To="Normal">
<Storyboard>
<PointerUpThemeAnimation Storyboard.TargetName="Grid" />
</Storyboard>
</VisualTransition>
<VisualTransition From="Pressed" To="Normal">
<Storyboard>
<PointerUpThemeAnimation Storyboard.TargetName="Grid" />
</Storyboard>
</VisualTransition>
</VisualStateGroup.Transitions>
</VisualStateGroup>
<VisualStateGroup x:Name="CheckStates">
<VisualState x:Name="Checked">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckGlyph" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Unchecked" />
<VisualState x:Name="Indeterminate">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="NormalRectangle" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid x:Name="Grid" Margin="{ThemeResource PhoneTouchTargetLargeOverhang}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25.5" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" VerticalAlignment="Top">
<Border x:Name="CheckBackground"
IsHitTestVisible="False"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Height="25.5"
Width="25.5" />
<Rectangle x:Name="NormalRectangle"
IsHitTestVisible="False"
Width="13"
Height="13"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Fill="{ThemeResource CheckBoxBackgroundThemeBrush}"
Visibility="Collapsed" />
<Path x:Name="CheckGlyph"
IsHitTestVisible="False"
Visibility="Collapsed"
Width="18.5"
Height="17"
Stretch="Fill"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Fill="{ThemeResource CheckBoxForegroundThemeBrush}"
Data="M0,123 L39,93 L124,164 L256,18 L295,49 L124,240 z"
StrokeLineJoin="Round"
StrokeThickness="2.5"
FlowDirection="LeftToRight" />
</Grid>
<ContentPresenter x:Name="ContentPresenter"
Grid.Column="1" Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Foreground="{TemplateBinding Foreground}"
FontFamily="{ThemeResource PhoneFontFamilyNormal}"
FontSize="{ThemeResource TextStyleLargeFontSize}"
FontWeight="Normal"
AutomationProperties.AccessibilityView="Raw" />
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
要将颜色更改为黑色,您需要将 CheckGlyph
Path
元素上的 Fill
属性 从 CheckBoxForegroundThemeBrush
更改为另一个值.或者您可以完全更改 CheckBox
控件的视觉外观。你可以自己做实验。
另一种方法是通过将以下任何资源添加到您的 App.xaml
来覆盖它们:
<SolidColorBrush x:Key="CheckBoxBorderThemeBrush" Color="Black" />
<SolidColorBrush x:Key="CheckBoxContentDisabledForegroundThemeBrush" />
<SolidColorBrush x:Key="CheckBoxContentForegroundThemeBrush" />
<SolidColorBrush x:Key="CheckBoxDisabledBorderThemeBrush" />
<SolidColorBrush x:Key="CheckBoxDisabledForegroundThemeBrush" />
<SolidColorBrush x:Key="CheckBoxForegroundThemeBrush" />
<SolidColorBrush x:Key="CheckBoxPointerOverBackgroundThemeBrush" />
<SolidColorBrush x:Key="CheckBoxPointerOverForegroundThemeBrush" />
<SolidColorBrush x:Key="CheckBoxPointerOverBorderThemeBrush" />
<SolidColorBrush x:Key="CheckBoxPressedBackgroundThemeBrush" />
<SolidColorBrush x:Key="CheckBoxPressedBorderThemeBrush" />
<SolidColorBrush x:Key="CheckBoxPressedForegroundThemeBrush" />
他们将更改的内容的含义是自我描述的,并且他们需要具有完全相同的名称。
您的 App.xaml
可能看起来像这样:
<Application
x:Class="MyApp"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
RequestedTheme="Light">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<!-- Overriden theme resources -->
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="CheckBoxBorderThemeBrush" Color="Black" />
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="CheckBoxBorderThemeBrush" Color="White" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<ResourceDictionary.MergedDictionaries>
<!-- Other resources -->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
至于 TimePicker
默认样式如下:
<Style TargetType="TimePicker">
<Setter Property="FontFamily" Value="{ThemeResource PhoneFontFamilyNormal}" />
<Setter Property="FontSize" Value="{ThemeResource ContentControlFontSize}" />
<Setter Property="Foreground" Value="{ThemeResource TimePickerForegroundThemeBrush}" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TimePicker">
<StackPanel Margin="{TemplateBinding Padding}" x:Name="LayoutRoot">
<ContentPresenter x:Name="HeaderContentPresenter" Style="{StaticResource HeaderContentPresenterStyle}" Margin="0,0,0,-3"
Content="{TemplateBinding Header}" ContentTemplate="{TemplateBinding HeaderTemplate}" />
<Button x:Name="FlyoutButton"
Foreground="{TemplateBinding Foreground}"
BorderBrush="{TemplateBinding Foreground}"
BorderThickness="2.5"
Padding="6.5,0,0,3"
IsEnabled="{TemplateBinding IsEnabled}"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
所以 TimePicker
header 颜色的解决方案是创建一个新的 TimePicker
样式,并设置 HeaderContentPresenter
元素的 Foreground
,或者您可以只更改 TimePicker
的 HeaderTemplate
而无需创建新样式:
<TimePicker Foreground="Black">
<TimePicker.Header>
<TextBlock Text="Header Text Example" Foreground="Black">
</TimePicker.Header>
</TimePicker>
或
<TimePicker Foreground="Black" Header="Header Text Example">
<TimePicker.HeaderTemplate>
<TextBlock Text="{Binding}" Foreground="Black">
</TimePicker.Header>
</TimePicker>