如何自定义TimePicker的样式

 我来答
雨过天晴日丶
2016-03-08 · TA获得超过2636个赞
知道大有可为答主
回答量:1879
采纳率:91%
帮助的人:1670万
展开全部
本主题介绍 TimePicker 控件的样式和模板。 你可以修改这些资源和默认 ControlTemplate 以便为该控件提供一个唯一的外观。
视觉状态
TimePicker 默认样式不定义任何视觉状态。
主题资源
这些资源在该控件的默认样式中使用。
深色主题画笔
若要在深色主题下更改该控件的颜色,请在 App.xaml 中替代这些画笔。
XAML
<SolidColorBrush x:Key="TimePickerHeaderForegroundThemeBrush" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="TimePickerForegroundThemeBrush" Color="#FF000000" />

浅色主题画笔
若要在浅色主题下更改该控件的颜色,请在 App.xaml 中替代这些画笔。
XAML
<SolidColorBrush x:Key="TimePickerHeaderForegroundThemeBrush" Color="#FF000000" />
<SolidColorBrush x:Key="TimePickerForegroundThemeBrush" Color="#FF000000" />

其他资源
XAML
<x:Double x:Key="TimePickerSelectorThemeMinWidth">80</x:Double>
<Thickness x:Key="TimePickerHeaderThemeMargin">0,0,0,6</Thickness>
<Thickness x:Key="TimePickerFirstHostThemeMargin">0,0,20,0</Thickness>
<Thickness x:Key="TimePickerThirdHostThemeMargin">20,0,0,0</Thickness>
<FontWeight x:Key="TimePickerHeaderThemeFontWeight">SemiLight</FontWeight>

共享资源
该控件模板使用这些与其他控件模板共享的资源。更改这些值将影响使用这些资源的其他控件。
XAML

<FontFamily x:Key="ContentControlThemeFontFamily">Segoe UI</FontFamily>
<x:Double x:Key="ControlContentThemeFontSize">14.667</x:Double>

有关主题资源的详细信息,包括用于 HighContrast 主题的值,请参阅 XAML 主题资源引用。
默认样式
XAML
<!-- Default style for Windows.UI.Xaml.Controls.TimePicker -->
<Style TargetType="TimePicker">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
<Setter Property="Foreground" Value="{ThemeResource TimePickerForegroundThemeBrush}"/>
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TimePicker">
<Border x:Name="LayoutRoot"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid Margin="{TemplateBinding Padding}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ContentPresenter x:Name="HeaderContentPresenter"
Foreground="{ThemeResource TimePickerHeaderForegroundThemeBrush}"
Margin="{ThemeResource TimePickerHeaderThemeMargin}"
FlowDirection="{TemplateBinding FlowDirection}"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
FontWeight="{ThemeResource TimePickerHeaderThemeFontWeight}" />
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Border x:Name="FirstPickerHost" Margin="{ThemeResource TimePickerFirstHostThemeMargin}">
<ComboBox x:Name="HourPicker"
MinWidth="{ThemeResource TimePickerSelectorThemeMinWidth}"
FontWeight="{TemplateBinding FontWeight}"
FontSize="{TemplateBinding FontSize}"
FontFamily="{TemplateBinding FontFamily}"
Foreground="{TemplateBinding Foreground}"/>
</Border>
<Border x:Name="SecondPickerHost">
<ComboBox x:Name="MinutePicker"
MinWidth="{ThemeResource TimePickerSelectorThemeMinWidth}"
FontWeight="{TemplateBinding FontWeight}"
FontSize="{TemplateBinding FontSize}"
FontFamily="{TemplateBinding FontFamily}"
Foreground="{TemplateBinding Foreground}"/>
</Border>
<Border x:Name="ThirdPickerHost" Margin="{ThemeResource TimePickerThirdHostThemeMargin}">
<ComboBox x:Name="PeriodPicker"
MinWidth="{ThemeResource TimePickerSelectorThemeMinWidth}"
FontWeight="{TemplateBinding FontWeight}"
FontSize="{TemplateBinding FontSize}"
FontFamily="{TemplateBinding FontFamily}"
Foreground="{TemplateBinding Foreground}"/>
</Border>
</StackPanel>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
匿名用户
2016-03-08
展开全部
本主题介绍 TimePicker 控件的样式和模板。 你可以修改这些资源和默认 ControlTemplate 以便为该控件提供一个唯一的外观。
视觉状态
TimePicker 默认样式不定义任何视觉状态。
主题资源
这些资源在该控件的默认样式中使用。
深色主题画笔
若要在深色主题下更改该控件的颜色,请在 App.xaml 中替代这些画笔。
XAML
<SolidColorBrush x:Key="TimePickerHeaderForegroundThemeBrush" Color="#FFFFFFFF" />
<SolidColorBrush x:Key="TimePickerForegroundThemeBrush" Color="#FF000000" />

浅色主题画笔
若要在浅色主题下更改该控件的颜色,请在 App.xaml 中替代这些画笔。
XAML
<SolidColorBrush x:Key="TimePickerHeaderForegroundThemeBrush" Color="#FF000000" />
<SolidColorBrush x:Key="TimePickerForegroundThemeBrush" Color="#FF000000" />

其他资源
XAML
<x:Double x:Key="TimePickerSelectorThemeMinWidth">80</x:Double>
<Thickness x:Key="TimePickerHeaderThemeMargin">0,0,0,6</Thickness>
<Thickness x:Key="TimePickerFirstHostThemeMargin">0,0,20,0</Thickness>
<Thickness x:Key="TimePickerThirdHostThemeMargin">20,0,0,0</Thickness>
<FontWeight x:Key="TimePickerHeaderThemeFontWeight">SemiLight</FontWeight>

共享资源
该控件模板使用这些与其他控件模板共享的资源。更改这些值将影响使用这些资源的其他控件。
XAML

<FontFamily x:Key="ContentControlThemeFontFamily">Segoe UI</FontFamily>
<x:Double x:Key="ControlContentThemeFontSize">14.667</x:Double>

有关主题资源的详细信息,包括用于 HighContrast 主题的值,请参阅 XAML 主题资源引用。
默认样式
XAML
<!-- Default style for Windows.UI.Xaml.Controls.TimePicker -->
<Style TargetType="TimePicker">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
<Setter Property="Foreground" Value="{ThemeResource TimePickerForegroundThemeBrush}"/>
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TimePicker">
<Border x:Name="LayoutRoot"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid Margin="{TemplateBinding Padding}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ContentPresenter x:Name="HeaderContentPresenter"
Foreground="{ThemeResource TimePickerHeaderForegroundThemeBrush}"
Margin="{ThemeResource TimePickerHeaderThemeMargin}"
FlowDirection="{TemplateBinding FlowDirection}"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
FontWeight="{ThemeResource TimePickerHeaderThemeFontWeight}" />
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Border x:Name="FirstPickerHost" Margin="{ThemeResource TimePickerFirstHostThemeMargin}">
<ComboBox x:Name="HourPicker"
MinWidth="{ThemeResource TimePickerSelectorThemeMinWidth}"
FontWeight="{TemplateBinding FontWeight}"
FontSize="{TemplateBinding FontSize}"
FontFamily="{TemplateBinding FontFamily}"
Foreground="{TemplateBinding Foreground}"/>
</Border>
<Border x:Name="SecondPickerHost">
<ComboBox x:Name="MinutePicker"
MinWidth="{ThemeResource TimePickerSelectorThemeMinWidth}"
FontWeight="{TemplateBinding FontWeight}"
FontSize="{TemplateBinding FontSize}"
FontFamily="{TemplateBinding FontFamily}"
Foreground="{TemplateBinding Foreground}"/>
</Border>
<Border x:Name="ThirdPickerHost" Margin="{ThemeResource TimePickerThirdHostThemeMargin}">
<ComboBox x:Name="PeriodPicker"
MinWidth="{ThemeResource TimePickerSelectorThemeMinWidth}"
FontWeight="{TemplateBinding FontWeight}"
FontSize="{TemplateBinding FontSize}"
FontFamily="{TemplateBinding FontFamily}"
Foreground="{TemplateBinding Foreground}"/>
</Border>
</StackPanel>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式