Files
ShrlAlgoToolkit/SyminUI/SyminUI/Themes/Styles/CalendarStyle.xaml

318 lines
20 KiB
Plaintext
Raw Normal View History

2025-07-11 09:20:23 +08:00
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sva="clr-namespace:SyminUI.Controls.Attach">
<!-- 年月按钮 -->
<Style x:Key="CalendarButtonDefault" TargetType="{x:Type CalendarButton}">
<Setter Property="Background" Value="{StaticResource Background.Main}" />
<Setter Property="BorderBrush" Value="{StaticResource PrimaryBrush}" />
<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" Visibility="Hidden"
StrokeThickness="{TemplateBinding BorderThickness}"
Fill="{StaticResource Background.SelectedMask}"
RadiusX="4" RadiusY="4" />
<Border x:Name="SelectedBorder" Margin="2" Visibility="Hidden"
CornerRadius="4" Background="{StaticResource PrimaryBrush}" />
<ContentPresenter x:Name="NormalText"
TextElement.Foreground="{StaticResource Text.Main}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="HasSelectedDays" Value="True">
<Setter Property="Visibility" TargetName="SelectedBorder"
Value="Visible" />
<Setter Property="TextElement.Foreground" TargetName="NormalText"
Value="{StaticResource Text.Contrast}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Visibility" TargetName="SelectionMark"
Value="Visible" />
<Setter Property="Background" TargetName="SelectedBorder"
Value="{StaticResource Primary.Focused}" />
</Trigger>
<Trigger Property="IsInactive" Value="True">
<Setter Property="TextElement.Foreground" TargetName="NormalText"
Value="{StaticResource Text.Secondary}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- 日期按钮 -->
<Style x:Key="CalendarDayButtonDefault" 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>
<VisualStateManager.VisualStateGroups>
<!-- 激活状态 -->
<VisualStateGroup x:Name="ActiveStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Active" />
<VisualState x:Name="Inactive">
<Storyboard>
<ColorAnimation Duration="0"
To="{StaticResource Text.SecondaryColor}"
Storyboard.TargetName="NormalText"
Storyboard.TargetProperty="(TextElement.Foreground)
.(SolidColorBrush.Color)" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<!-- 选中背景 -->
<Rectangle x:Name="SelectedBackground" Visibility="Hidden"
Fill="{StaticResource Background.FocusedMask}"
RadiusX="4" RadiusY="4" />
<!-- 鼠标划过背景 -->
<Rectangle x:Name="HighlightBackground" Visibility="Hidden"
Fill="{StaticResource Background.SelectedMask}"
RadiusX="4" RadiusY="4" />
<!-- 今日背景 -->
<Rectangle x:Name="TodayBackground" Visibility="Hidden"
Fill="{StaticResource PrimaryBrush}"
Stroke="{StaticResource SecondaryBrush}"
StrokeThickness="0"
RadiusX="4" RadiusY="4" />
<ContentPresenter x:Name="NormalText"
TextElement.Foreground="{StaticResource Text.Main}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="5,1,5,1" />
<!-- 叉 -->
<Path x:Name="Blackout"
Data="M0,10 L10,0"
Stroke="{StaticResource DangerBrush}"
StrokeThickness="2" Margin="4" Opacity="0"
RenderTransformOrigin="0.5,0.5" Stretch="Uniform" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Visibility" TargetName="HighlightBackground"
Value="Visible"/>
<Setter Property="Fill" TargetName="TodayBackground"
Value="{StaticResource Primary.Focused}"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="StrokeThickness" TargetName="TodayBackground"
Value="1"/>
<Setter Property="Visibility" TargetName="SelectedBackground"
Value="Visible"/>
</Trigger>
<Trigger Property="IsToday" Value="True">
<Setter Property="TextElement.Foreground" TargetName="NormalText"
Value="{StaticResource Text.Contrast}"/>
<Setter Property="Visibility" TargetName="TodayBackground"
Value="Visible"/>
</Trigger>
<Trigger Property="IsBlackedOut" Value="True">
<Setter Property="Visibility" TargetName="Blackout"
Value="Visible" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<!--TODO:设置禁用效果-->
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="CalendarItemDefault" TargetType="{x:Type CalendarItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CalendarItem}">
<ControlTemplate.Resources>
<!-- 星期标题 -->
<DataTemplate x:Key="{x:Static CalendarItem.DayTitleTemplateResourceKey}">
<TextBlock Foreground="{StaticResource Additional.Blue}"
FontFamily="Verdana" FontWeight="Bold" FontSize="12"
HorizontalAlignment="Center"
Margin="0,6,0,6" Text="{Binding}"
VerticalAlignment="Center" />
</DataTemplate>
</ControlTemplate.Resources>
<Grid x:Name="PART_Root">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimation Duration="0" To="0.5"
Storyboard.TargetName="PART_DisabledVisual"
Storyboard.TargetProperty="Opacity" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Effect="{StaticResource PopupShadow}"
CornerRadius="8" Margin="4">
<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"
Background="{StaticResource PrimaryBrush}"
CornerRadius="6,6,0,0"
Margin="2" />
<!-- 向左按钮 -->
<Button x:Name="PART_PreviousButton" Grid.Column="0" Grid.Row="0"
Focusable="False" Padding="8" Margin="3"
Background="{StaticResource PrimaryBrush}"
Style="{StaticResource ButtonFlatten}">
<Path Data="{StaticResource LeftArrow}"
Fill="{StaticResource Text.Contrast}"
Stretch="Uniform" Width="8" Height="8" />
</Button>
<!-- 中间按钮 -->
<Button x:Name="PART_HeaderButton" Grid.Column="1" Grid.Row="0"
sva:ShadingElement.DisabledForeground="{StaticResource Text.Contrast.Disabled}"
Background="{StaticResource PrimaryBrush}"
Foreground="{StaticResource Text.Contrast}"
Focusable="False" Margin="0,3"
FontWeight="Bold" FontSize="12"
Style="{StaticResource ButtonFlatten}"
HorizontalAlignment="Stretch" />
<!-- 右侧按钮 -->
<Button x:Name="PART_NextButton" Grid.Column="2" Grid.Row="0"
Background="{StaticResource PrimaryBrush}"
Focusable="False" Padding="8" Margin="3"
Style="{StaticResource ButtonFlatten}">
<Path Data="{StaticResource RightArrow}"
Fill="{StaticResource Text.Contrast}"
Stretch="Uniform" Width="8" Height="8" />
</Button>
<!-- 月份视图 -->
<Grid x:Name="PART_MonthView"
Grid.ColumnSpan="3" HorizontalAlignment="Center"
Margin="6,2,6,6" Grid.Row="1" 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.ColumnSpan="3" HorizontalAlignment="Center"
Margin="6,2,6,6" Grid.Row="1" 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" Opacity="0"
Fill="{StaticResource Background.Main}"
RadiusX="6" RadiusY="6" Margin="4"
Stretch="Fill" Visibility="Collapsed" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Visibility" TargetName="PART_DisabledVisual" Value="Visible" />
</Trigger>
<DataTrigger
Binding="{Binding DisplayMode,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Calendar}}}"
Value="Year">
<Setter Property="Visibility" TargetName="PART_MonthView" Value="Hidden" />
<Setter Property="Visibility" TargetName="PART_YearView" Value="Visible" />
</DataTrigger>
<DataTrigger
Binding="{Binding DisplayMode,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Calendar}}}"
Value="Decade">
<Setter Property="Visibility" TargetName="PART_MonthView" Value="Hidden" />
<Setter Property="Visibility" TargetName="PART_YearView" Value="Visible" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="CalendarDefault" TargetType="{x:Type Calendar}">
<Setter Property="CalendarItemStyle" Value="{StaticResource CalendarItemDefault}" />
<Setter Property="CalendarDayButtonStyle" Value="{StaticResource CalendarDayButtonDefault}" />
<Setter Property="CalendarButtonStyle" Value="{StaticResource CalendarButtonDefault}" />
<Setter Property="Background" Value="{StaticResource Background.Main}" />
<Setter Property="BorderBrush" Value="{StaticResource Border.Main.Shaded}" />
<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 TargetType="{x:Type Calendar}" BasedOn="{StaticResource CalendarDefault}" />
<Style x:Key="PickerCalendarStyle"
TargetType="{x:Type Calendar}" BasedOn="{StaticResource CalendarDefault}" >
<Setter Property="Margin" Value="8"/>
</Style>
</ResourceDictionary>