如何自定义TimePicker的样式
2个回答
展开全部
本主题介绍 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>
视觉状态
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>
视觉状态
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>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询