自定义日历控件Calendar样式

日历样式,图放上来了,之后补充下讲解吧



默认样式显示是“标题年月+显示日”,图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
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值