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

342 lines
19 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:Melskin.Controls">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="FlattenButton.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- 年月按钮 -->
<Style x:Key="DefaultCalendarButtonStyle" TargetType="{x:Type CalendarButton}">
<Setter Property="Background" Value="{DynamicResource BackgroundLayoutBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryNormalBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="MinWidth" Value="48" />
<Setter Property="MinHeight" Value="42" />
<Setter Property="FontSize" Value="12" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CalendarButton}">
<Grid>
<Rectangle
x:Name="SelectionMark"
Margin="2"
Fill="{DynamicResource ControlBackgroundSelectedBrush}"
RadiusX="4"
RadiusY="4"
StrokeThickness="{TemplateBinding BorderThickness}"
Visibility="Hidden" />
<Border
x:Name="SelectedBorder"
Margin="2"
Background="{DynamicResource PrimaryNormalBrush}"
CornerRadius="4"
Visibility="Hidden" />
<ContentPresenter
x:Name="NormalText"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
TextElement.Foreground="{DynamicResource TextPrimaryBrush}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="HasSelectedDays" Value="True">
<Setter TargetName="SelectedBorder" Property="Visibility" Value="Visible" />
<Setter TargetName="NormalText" Property="TextElement.Foreground" Value="{DynamicResource TextAccentBrush}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="SelectionMark" Property="Visibility" Value="Visible" />
<Setter TargetName="SelectedBorder" Property="Background" Value="{DynamicResource PrimaryFocusedBrush}" />
</Trigger>
<Trigger Property="IsInactive" Value="True">
<Setter TargetName="NormalText" Property="TextElement.Foreground" Value="{DynamicResource TextSecondaryBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- 日期按钮 -->
<Style x:Key="DefaultCalendarDayButtonStyle" TargetType="{x:Type CalendarDayButton}">
<Setter Property="MinWidth" Value="28" />
<Setter Property="MinHeight" Value="26" />
<Setter Property="FontSize" Value="12" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CalendarDayButton}">
<Grid>
<!-- 选中背景 -->
<Rectangle
x:Name="SelectedBackground"
Fill="{DynamicResource ControlBackgroundSelectedBrush}"
RadiusX="4"
RadiusY="4"
Visibility="Hidden" />
<!-- 鼠标划过背景 -->
<Rectangle
x:Name="HighlightBackground"
Fill="{DynamicResource ControlBackgroundHoverBrush}"
RadiusX="4"
RadiusY="4"
Visibility="Hidden" />
<!-- 今日背景 -->
<Rectangle
x:Name="TodayBackground"
Fill="{DynamicResource PrimaryNormalBrush}"
RadiusX="4"
RadiusY="4"
Stroke="{DynamicResource PrimaryVariantBrush}"
StrokeThickness="0"
Visibility="Hidden" />
<ContentPresenter
x:Name="NormalText"
Margin="5,1,5,1"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
TextElement.Foreground="{DynamicResource TextPrimaryBrush}" />
<!---->
<controls:IconElement
x:Name="Blackout"
Margin="4"
Foreground="{DynamicResource ErrorBrush}"
Opacity="0"
RenderTransformOrigin="0.5,0.5"
Symbol="Close" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="HighlightBackground" Property="Visibility" Value="Visible" />
<Setter TargetName="TodayBackground" Property="Fill" Value="{DynamicResource PrimaryFocusedBrush}" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="TodayBackground" Property="StrokeThickness" Value="1" />
<Setter TargetName="SelectedBackground" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="IsToday" Value="True">
<Setter TargetName="NormalText" Property="TextElement.Foreground" Value="#e0e0e0" />
<Setter TargetName="TodayBackground" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="IsBlackedOut" Value="True">
<Setter TargetName="Blackout" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
</Trigger>
<Trigger Property="IsInactive" Value="True">
<Setter TargetName="NormalText" Property="TextElement.Foreground" Value="{DynamicResource TextSecondaryBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="DefaultCalendarItemStyle" TargetType="{x:Type CalendarItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CalendarItem}">
<ControlTemplate.Resources>
<!-- 星期标题 -->
<DataTemplate x:Key="{x:Static CalendarItem.DayTitleTemplateResourceKey}">
<TextBlock
Margin="0,6,0,6"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontFamily="Verdana"
FontSize="12"
FontWeight="Bold"
Foreground="{DynamicResource PrimaryVariantBrush}"
Text="{Binding}" />
</DataTemplate>
</ControlTemplate.Resources>
<Grid x:Name="PART_Root">
<Border
Margin="4"
Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="8"
Effect="{DynamicResource PopupShadow}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="32" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="32" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- 上方背景 -->
<Border
Grid.ColumnSpan="3"
Margin="2"
Background="{DynamicResource PrimaryNormalBrush}"
CornerRadius="6,6,0,0" />
<!-- 向左按钮 -->
<Button
x:Name="PART_PreviousButton"
Grid.Row="0"
Grid.Column="0"
Margin="3"
Padding="4"
Background="{DynamicResource PrimaryNormalBrush}"
Focusable="False"
Style="{StaticResource FlattenButtonStyle}">
<controls:IconElement Foreground="#e0e0e0" Symbol="ArrowBackIos" />
</Button>
<!-- 中间按钮 -->
<Button
x:Name="PART_HeaderButton"
Grid.Row="0"
Grid.Column="1"
Margin="0,3"
HorizontalAlignment="Stretch"
Background="{DynamicResource PrimaryNormalBrush}"
Focusable="False"
FontSize="12"
FontWeight="Bold"
Foreground="#e0e0e0"
Style="{StaticResource FlattenButtonStyle}" />
<!-- 右侧按钮 -->
<Button
x:Name="PART_NextButton"
Grid.Row="0"
Grid.Column="2"
Margin="3"
Padding="4"
Background="{DynamicResource PrimaryNormalBrush}"
Focusable="False"
Style="{StaticResource FlattenButtonStyle}">
<controls:IconElement Foreground="#e0e0e0" Symbol="ArrowForwardIos" />
</Button>
<!-- 月份视图 -->
<Grid
x:Name="PART_MonthView"
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="3"
Margin="6,2,6,6"
HorizontalAlignment="Center"
Visibility="Visible">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
</Grid>
<!-- 年份视图 -->
<Grid
x:Name="PART_YearView"
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="3"
Margin="6,2,6,6"
HorizontalAlignment="Center"
Visibility="Hidden">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
</Grid>
</Grid>
</Border>
<!-- 禁用遮罩 -->
<Rectangle
x:Name="PART_DisabledVisual"
Margin="4"
Fill="{DynamicResource ControlBackgroundDisabledBrush}"
Opacity="0"
RadiusX="6"
RadiusY="6"
Stretch="Fill"
Visibility="Collapsed" />
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="PART_DisabledVisual"
Storyboard.TargetProperty="Opacity"
To="0.5"
Duration="0" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="PART_DisabledVisual" Property="Visibility" Value="Visible" />
</Trigger>
<DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}}" Value="Year">
<Setter TargetName="PART_MonthView" Property="Visibility" Value="Hidden" />
<Setter TargetName="PART_YearView" Property="Visibility" Value="Visible" />
</DataTrigger>
<DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}}" Value="Decade">
<Setter TargetName="PART_MonthView" Property="Visibility" Value="Hidden" />
<Setter TargetName="PART_YearView" Property="Visibility" Value="Visible" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="DefaultCalendarStyle" TargetType="{x:Type Calendar}">
<Setter Property="CalendarItemStyle" Value="{StaticResource DefaultCalendarItemStyle}" />
<Setter Property="CalendarDayButtonStyle" Value="{StaticResource DefaultCalendarDayButtonStyle}" />
<Setter Property="CalendarButtonStyle" Value="{StaticResource DefaultCalendarButtonStyle}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderGradientBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Calendar}">
<StackPanel x:Name="PART_Root" HorizontalAlignment="Center">
<CalendarItem
x:Name="PART_CalendarItem"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Style="{TemplateBinding CalendarItemStyle}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style BasedOn="{StaticResource DefaultCalendarStyle}" TargetType="{x:Type Calendar}" />
<Style
x:Key="DefaultCalendarPickerStyle"
BasedOn="{StaticResource DefaultCalendarStyle}"
TargetType="{x:Type Calendar}">
<Setter Property="Margin" Value="8" />
</Style>
</ResourceDictionary>