Files
ShrlAlgoToolkit/WPFluent/Controls/DatePicker/DatePicker.xaml
ShrlAlgo 4d35cadb56 更新
2025-07-11 09:20:23 +08:00

206 lines
13 KiB
XML

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:WPFluent.Controls"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/WPFluent;component/Resources/Variables.xaml" />
<!--<ResourceDictionary Source="/WPFluent;component/Themes/Light.xaml" />-->
</ResourceDictionary.MergedDictionaries>
<Thickness x:Key="DatePickerBorderThemeThickness">1,1,1,0</Thickness>
<Thickness x:Key="DatePickerAccentBorderThemeThickness">0,0,0,1</Thickness>
<Thickness x:Key="DatePickerLeftIconMargin">10,8,0,0</Thickness>
<Thickness x:Key="DatePickerRightIconMargin">0,8,10,0</Thickness>
<Thickness x:Key="DatePickerCalendarButtonMargin">0,5,4,0</Thickness>
<Thickness x:Key="DatePickerCalendarButtonPadding">0,0,0,0</Thickness>
<system:Double x:Key="DatePickerCalendarButtonHeight">24</system:Double>
<system:Double x:Key="DatePickerCalendarButtonIconSize">14</system:Double>
<Style x:Key="DefaultDatePickerTextBoxStyle" TargetType="{x:Type DatePickerTextBox}">
<!-- Universal WPF UI focus -->
<Setter Property="FocusVisualStyle" Value="{DynamicResource DefaultControlFocusVisualStyle}" />
<!-- Universal WPF UI focus -->
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="CaretBrush">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource TextFillColorPrimary}" />
</Setter.Value>
</Setter>
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource TextFillColorPrimary}" />
</Setter.Value>
</Setter>
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DatePickerTextBox}">
<Border Margin="{TemplateBinding Margin}">
<Decorator x:Name="PART_ContentHost" Margin="{TemplateBinding Padding}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="VerticalContentAlignment" Value="Stretch" />
</Style>
<Style x:Key="DefaultDatePickerStyle" TargetType="{x:Type DatePicker}">
<!-- Universal WPF UI focus -->
<!-- Universal WPF UI focus -->
<!-- Universal WPF UI ContextMenu -->
<!-- Universal WPF UI ContextMenu -->
<!-- Default WPF UI Calendar style -->
<!-- Default WPF UI Calendar style -->
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource ControlFillColorDefault}" />
</Setter.Value>
</Setter>
<Setter Property="Border.CornerRadius" Value="{StaticResource ControlCornerRadius}" />
<Setter Property="BorderBrush" Value="{DynamicResource ControlElevationBorderBrush}" />
<Setter Property="BorderThickness" Value="{StaticResource DatePickerBorderThemeThickness}" />
<Setter Property="CalendarStyle" Value="{DynamicResource DefaultCalendarStyle}" />
<Setter Property="ContextMenu" Value="{DynamicResource DefaultControlContextMenu}" />
<Setter Property="FocusVisualStyle" Value="{DynamicResource DefaultControlFocusVisualStyle}" />
<Setter Property="FontSize" Value="{StaticResource ControlContentThemeFontSize}" />
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource TextFillColorPrimary}" />
</Setter.Value>
</Setter>
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="MinHeight" Value="{StaticResource TextControlThemeMinHeight}" />
<Setter Property="MinWidth" Value="{StaticResource TextControlThemeMinWidth}" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Padding" Value="{StaticResource TextControlThemePadding}" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DatePicker}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid
Grid.Row="0"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Border
x:Name="ContentBorder"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
MinWidth="{TemplateBinding MinWidth}"
MinHeight="{TemplateBinding MinHeight}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}"
Padding="0">
<Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<DatePickerTextBox
x:Name="PART_TextBox"
Margin="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ContextMenu="{TemplateBinding ContextMenu}"
Focusable="{TemplateBinding Focusable}"
Foreground="{TemplateBinding Foreground}"
Padding="{TemplateBinding Padding}" />
</Grid>
<!-- Buttons and Icons have no padding from the main element to allow absolute positions if height is larger than the text entry zone -->
<controls:Button
x:Name="PART_Button"
Grid.Column="1"
Width="{StaticResource DatePickerCalendarButtonHeight}"
Height="{StaticResource DatePickerCalendarButtonHeight}"
Margin="{StaticResource DatePickerCalendarButtonMargin}"
HorizontalAlignment="Center"
VerticalAlignment="Top"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Appearance="Primary"
Background="Transparent"
BorderBrush="Transparent"
Cursor="Arrow"
Padding="{StaticResource DatePickerCalendarButtonPadding}">
<!-- WPF overrides paddings for button -->
<controls:SymbolIcon
Margin="{StaticResource DatePickerCalendarButtonPadding}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="{StaticResource DatePickerCalendarButtonIconSize}"
Foreground="{TemplateBinding Foreground}"
Symbol="CalendarRtl24" />
</controls:Button>
</Grid>
</Border>
<!-- The Accent Border is a separate element so that changes to the border thickness do not affect the position of the element -->
<Border
x:Name="AccentBorder"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
BorderThickness="{StaticResource DatePickerAccentBorderThemeThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}">
<Border.BorderBrush>
<SolidColorBrush Color="{DynamicResource ControlStrongStrokeColorDefault}" />
</Border.BorderBrush>
</Border>
</Grid>
<Popup
x:Name="PART_Popup"
Grid.Row="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
AllowsTransparency="True"
Placement="Mouse"
PlacementTarget="{Binding ElementName=PART_TextBox}"
StaysOpen="False" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource ControlFillColorInputActiveBrush}" />
<Setter TargetName="AccentBorder" Property="BorderBrush" Value="{DynamicResource AccentFillColorSecondaryBrush}" />
<Setter TargetName="AccentBorder" Property="BorderThickness" Value="0,0,0,2" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsEnabled" Value="True" />
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsKeyboardFocusWithin" Value="False" />
</MultiTrigger.Conditions>
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource ControlFillColorSecondaryBrush}" />
</MultiTrigger>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Cursor" Value="IBeam" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource ControlFillColorDisabledBrush}" />
<Setter TargetName="ContentBorder" Property="BorderBrush" Value="{DynamicResource ControlStrokeColorDefaultBrush}" />
<Setter TargetName="AccentBorder" Property="BorderBrush" Value="{DynamicResource ControlStrokeColorDefaultBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextFillColorDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Top" />
</Style>
<Style BasedOn="{StaticResource DefaultDatePickerTextBoxStyle}" TargetType="{x:Type DatePickerTextBox}" />
<Style BasedOn="{StaticResource DefaultDatePickerStyle}" TargetType="{x:Type DatePicker}" />
</ResourceDictionary>