Files
ShrlAlgoToolkit/Melskin/Controls/DatePicker.xaml
2026-02-20 15:31:44 +08:00

444 lines
24 KiB
XML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:assists="clr-namespace:Melskin.Assists"
xmlns:decorations="clr-namespace:Melskin.Controls.Decorations"
xmlns:effects="clr-namespace:Melskin.Effects">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Calendar.xaml" />
<ResourceDictionary Source="/Melskin;component/Themes/Animations.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style x:Key="SlotTextBoxDatePickerStyle" TargetType="{x:Type DatePickerTextBox}">
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="Padding" Value="3" />
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DatePickerTextBox}">
<!--<ControlTemplate.Resources>
-->
<!-- 聚焦对象 -->
<!--
<Storyboard x:Key="TextBox.FocusEffect">
<DoubleAnimation
Duration="0:0:0.2"
Storyboard.TargetName="Border"
Storyboard.TargetProperty="Intensity"
To="0.5" />
</Storyboard>
-->
<!-- 取消聚焦对象 -->
<!--
<Storyboard x:Key="TextBox.LeaveEffect">
<DoubleAnimation
Duration="0:0:0.2"
Storyboard.TargetName="Border"
Storyboard.TargetProperty="Intensity"
To="0.2" />
</Storyboard>
</ControlTemplate.Resources>-->
<Grid>
<Grid>
<decorations:SlotBorder
x:Name="slot"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Intensity="0.4">
<ContentControl
x:Name="PART_Watermark"
Margin="5,0,0,0"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Focusable="False"
IsHitTestVisible="False"
Opacity="0" />
</decorations:SlotBorder>
<ScrollViewer
x:Name="PART_ContentHost"
Margin="6,0,0,0"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
</Grid>
<VisualStateManager.VisualStateGroups>
<!-- 占位符显示 -->
<!-- https://learn.microsoft.com/en-us/dotnet/desktop/wpf/controls/datepicker-styles-and-templates -->
<!-- DataPicker自带有这个状态所以可以直接生效 -->
<VisualStateGroup x:Name="WatermarkStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Unwatermarked" />
<VisualState x:Name="Watermarked">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="PART_Watermark"
Storyboard.TargetProperty="Opacity"
To="1"
Duration="0" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="false" />
<Condition Property="IsKeyboardFocused" Value="false" />
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource TextBox.LeaveEffect}" />
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource TextBox.FocusEffect}" />
</MultiTrigger.ExitActions>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="DefaultTextBoxDatePickerStyle" TargetType="{x:Type DatePickerTextBox}">
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="Background" Value="{DynamicResource BackgroundFloatingBrush}" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DatePickerTextBox}">
<Grid>
<Grid>
<Border
x:Name="Border"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding assists:ControlAssist.CornerRadius}">
<ContentControl
x:Name="PART_Watermark"
Margin="5,0,0,0"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Focusable="False"
IsHitTestVisible="False"
Opacity="0" />
</Border>
<ScrollViewer
x:Name="PART_ContentHost"
Margin="4,0,0,0"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
</Grid>
<VisualStateManager.VisualStateGroups>
<!-- 占位符显示 -->
<!-- https://learn.microsoft.com/en-us/dotnet/desktop/wpf/controls/datepicker-styles-and-templates -->
<!-- DataPicker自带有这个状态所以可以直接生效 -->
<VisualStateGroup x:Name="WatermarkStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Unwatermarked" />
<VisualState x:Name="Watermarked">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="PART_Watermark"
Storyboard.TargetProperty="Opacity"
To="1"
Duration="0" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource PrimaryNormalBrush}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="Background" Value="{DynamicResource ControlBackgroundHoverBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!--<Style BasedOn="{StaticResource DefaultTextBoxDatePickerStyle}" TargetType="{x:Type DatePickerTextBox}" />-->
<ControlTemplate x:Key="SlotTemplate" TargetType="{x:Type DatePicker}">
<ControlTemplate.Resources>
<Style x:Key="CalendarPickerButton" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="IconBox">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="2*" />
</Grid.RowDefinitions>
<Border
Grid.Row="0"
Background="{DynamicResource PrimaryGradientBrush}"
CornerRadius="3,3,0,0" />
<Border
Grid.Row="1"
Background="{DynamicResource BackgroundFloatingBrush}"
CornerRadius="0,0,3,3" />
<TextBlock
Grid.Row="0"
HorizontalAlignment="Center"
FontSize="8"
FontWeight="ExtraBold"
Foreground="{DynamicResource BackgroundFloatingBrush}"
Text="TEN" />
<TextBlock
Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Stretch"
FontWeight="ExtraBold"
Foreground="{DynamicResource TextSecondaryBrush}"
Text="18" />
<Grid.Effect>
<DropShadowEffect
BlurRadius="4"
Opacity="0.6"
ShadowDepth="1"
Color="{DynamicResource DarkShadowColor}" />
</Grid.Effect>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Effect">
<Setter.Value>
<effects:BrightnessContrastEffect Brightness="0.08" />
</Setter.Value>
</Setter>
<Setter TargetName="IconBox" Property="Effect">
<Setter.Value>
<DropShadowEffect
BlurRadius="4"
Opacity="0.4"
ShadowDepth="1"
Color="{DynamicResource DarkShadowColor}" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Effect">
<Setter.Value>
<effects:BrightnessContrastEffect Brightness="0.06" />
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ControlTemplate.Resources>
<Grid
x:Name="PART_Root"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="True">
<DatePickerTextBox
x:Name="PART_TextBox"
Grid.Row="0"
Grid.Column="0"
HorizontalContentAlignment="Left"
VerticalContentAlignment="Center"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Focusable="{TemplateBinding Focusable}"
Style="{StaticResource SlotTextBoxDatePickerStyle}" />
<Border
Width="40"
HorizontalAlignment="Right"
Background="Transparent" />
<Button
x:Name="PART_Button"
Width="28"
Margin="5"
HorizontalAlignment="Right"
Style="{StaticResource CalendarPickerButton}" />
<!-- Disabled Mask -->
<Border
x:Name="DisabledMask"
Margin="4"
Background="{DynamicResource ControlBackgroundDisabledBrush}"
CornerRadius="4"
IsHitTestVisible="False"
Opacity="0" />
<Popup
x:Name="PART_Popup"
assists:BehaviorAssist.SimulateNativeBehavior="True"
AllowsTransparency="True"
Placement="Bottom"
PlacementTarget="{Binding ElementName=PART_Button}"
StaysOpen="True" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="DisabledMask" Property="Opacity" Value="0.6" />
</Trigger>
<DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="false">
<Setter TargetName="PART_TextBox" Property="Foreground" Value="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="DefaultTemplate" TargetType="{x:Type DatePicker}">
<ControlTemplate.Resources>
<Style x:Key="CalendarPickerButton" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="IconBox">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="2*" />
</Grid.RowDefinitions>
<Border
Grid.Row="0"
Background="{DynamicResource PrimaryGradientBrush}"
CornerRadius="3,3,0,0" />
<Border
Grid.Row="1"
Background="{DynamicResource BackgroundFloatingBrush}"
CornerRadius="0,0,3,3" />
<TextBlock
Grid.Row="0"
HorizontalAlignment="Center"
FontSize="8"
FontWeight="ExtraBold"
Foreground="{DynamicResource BackgroundFloatingBrush}"
Text="TEN" />
<TextBlock
Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Stretch"
FontWeight="ExtraBold"
Foreground="{DynamicResource TextSecondaryBrush}"
Text="18" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Effect">
<Setter.Value>
<effects:BrightnessContrastEffect Brightness="0.08" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Effect">
<Setter.Value>
<effects:BrightnessContrastEffect Brightness="0.06" />
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ControlTemplate.Resources>
<Grid
x:Name="PART_Root"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="True">
<DatePickerTextBox
x:Name="PART_TextBox"
Grid.Row="0"
Grid.Column="0"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Left"
VerticalContentAlignment="Center"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Focusable="{TemplateBinding Focusable}"
Style="{StaticResource DefaultTextBoxDatePickerStyle}" />
<Border
Width="40"
HorizontalAlignment="Right"
Background="Transparent" />
<Button
x:Name="PART_Button"
Width="28"
Margin="5"
HorizontalAlignment="Right"
Style="{StaticResource CalendarPickerButton}" />
<!-- Disabled Mask -->
<Border
x:Name="DisabledMask"
Background="{DynamicResource ControlBackgroundDisabledBrush}"
CornerRadius="4"
IsHitTestVisible="False"
Opacity="0" />
<Popup
x:Name="PART_Popup"
assists:BehaviorAssist.SimulateNativeBehavior="True"
AllowsTransparency="True"
Placement="Bottom"
PlacementTarget="{Binding ElementName=PART_Button}"
StaysOpen="True" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="DisabledMask" Property="Opacity" Value="0.6" />
</Trigger>
<DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="false">
<Setter TargetName="PART_TextBox" Property="Foreground" Value="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<!-- 日期图标按钮 -->
<Style x:Key="SlotDatePicker" TargetType="{x:Type DatePicker}">
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="IsTodayHighlighted" Value="True" />
<Setter Property="SelectedDateFormat" Value="Short" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="Padding" Value="0" />
<!--<Setter Property="Margin" Value="0"/>-->
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="CalendarStyle" Value="{StaticResource DefaultCalendarPickerStyle}" />
<Setter Property="MinWidth" Value="150" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Template" Value="{StaticResource SlotTemplate}" />
</Style>
<Style TargetType="{x:Type DatePicker}">
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="IsTodayHighlighted" Value="True" />
<Setter Property="SelectedDateFormat" Value="Short" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="CalendarStyle" Value="{StaticResource DefaultCalendarPickerStyle}" />
<Setter Property="MinWidth" Value="150" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Template" Value="{StaticResource DefaultTemplate}" />
</Style>
</ResourceDictionary>