日历样式,图放上来了,之后补充下讲解吧
默认样式显示是“标题年月+显示日”,图1右箭头是鼠标附上去时的颜色。
点击顶上的标题,“标题年月+显示日”切换为“标题年+显示月”;“标题该年+显示月”切换为“标题年范围+显示年”。
默认没有选中当日,这个可以在样式里设置回来,有注释应该可以看明白,不清楚的可以本地改几句属性试试看!~
可以直接运行测试
<Window x:Class="WpfTest.forTEST"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" WindowStartupLocation="CenterScreen" ShowInTaskbar="False" Background="{x:Null}" AllowsTransparency="True"
Height="286" Width="339">
<Window.Resources>
<!--日历日期面板样式-->
<Style x:Key="CalendarItemStyle1" TargetType="{x:Type CalendarItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CalendarItem}">
<ControlTemplate.Resources>
<!-- 头部星期样式-->
<DataTemplate x:Key="{x:Static CalendarItem.DayTitleTemplateResourceKey}">
<TextBlock Text="{Binding}" FontFamily="FZLTZHUNHK" Foreground="#FF707274" FontSize="18"
HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,6,0,0"/>
</DataTemplate>
</ControlTemplate.Resources>
<Grid x:Name="PART_Root">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="38" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!--Header-->
<Grid Grid.Row="0" HorizontalAlignment="Stretch" Background="#FF035BC7">
<Grid.Resources>
<!--日历头左箭头按钮样式模版-->
<ControlTemplate x:Key="PreviousButtonTemplate"
TargetType="{x:Type Button}">
<!--鼠标悬停在左箭头按钮上时改变鼠标指针样式-->
<Grid Cursor="Hand">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver">
<!--鼠标悬停在左箭头按钮上时左箭头颜色变化动画-->
<Storyboard>
<ColorAnimation Duration="0"
To="#FF73A9D8"
Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)"
Storyboard.TargetName="path" />
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimation Duration="0"
To=".5"
Storyboard.TargetProperty="(Shape.Fill).(Brush.Opacity)"
Storyboard.TargetName="path" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<!--左箭头整个区域矩形块-->
<Rectangle Fill="#FF035BC7"
Opacity="1"
Stretch="Fill" />
<Grid>
<!--左箭头-->
<Path x:Name="path"
Data="M288.75,232.25 L288.75,240.625 L283,236.625 z"
Fill="#FFFFFFFF"
Horizo