WPF自定义日历控件Calendar 的方法

推荐下载地址 https://www.haolizi.net/example/view_2107.html

<UserControl.Resources>
        <local1:DayConverter x:Key="DayConverter"/><!--导入转换器-->
        <Style x:Key="CalendarStyle1"
                TargetType="{x:Type Calendar}">
            <!--日历控件的背景色,也可以改成绑定的-->
            <Setter Property = "Background"
                     Value="#f6f6f6" />
            <Setter Property = "Template" >
                <Setter.Value >
                    <ControlTemplate TargetType="{x:Type Calendar}">

                        <StackPanel x:Name="PART_Root"
                                     HorizontalAlignment="Center"
                                     VerticalAlignment="Center">
                            <!--这个是日历控件的主体元件,也是内部元件PART_CalendarItem名称不要更改,可以改它的其它样式属性-->
                            <CalendarItem x:Name="PART_CalendarItem"
                                           BorderBrush="{TemplateBinding BorderBrush}"
                                           BorderThickness="{TemplateBinding BorderThickness}"
                                           Background="{TemplateBinding Background}"
                                           Style="{TemplateBinding CalendarItemStyle}"
                                           Height="{TemplateBinding Height}"
                                           Width="{TemplateBinding Width}"
                                           HorizontalAlignment="Stretch"
                                           VerticalAlignment="Stretch" />
                        </StackPanel>

                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!--日历主体样式表-->
        <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 Foreground = "#666666"
                                            FontSize="16"
                                            FontFamily="微软雅黑"
                                            HorizontalAlignment="Center"
                                            Margin="0 15"
                                            Text="{Binding StringFormat=周{0} }"
                                            VerticalAlignment="Center" />
                            </DataTemplate>
                        </ControlTemplate.Resources>
                        <Grid x:Name="PART_Root">
                            <Grid.Resources>
                                <!--设置日历控件 IsEnable = false 时的不可用遮罩层颜色,并且会播放过渡动画-->
                                <SolidColorBrush x:Key="DisabledColor"
                                                  Color="#A5FFFFFF" />
                            </Grid.Resources>


                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal" />
                                    <VisualState x:Name="Disabled">
                                        <!--设置日历控件 IsEnable = false 时遮罩层透明度0-1变色动画-->
                                        <Storyboard>
                                            <DoubleAnimation Duration = "0"
                                                              To="1"
                                                              Storyboard.TargetProperty="Opacity"
                                                              Storyboard.TargetName="PART_DisabledVisual" />
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>

                            <Border BorderBrush = "#cfcfcf"
                                    BorderThickness="0"
                                    Background="{TemplateBinding Background}"
                                    CornerRadius="2">
                                <Border>
                                    <Grid>
                                        <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 = "#363636"
                                                               Opacity="1"
                                                               Stretch="Fill" />
                                                    <Grid>
                                                        <!--左箭头-->
                                                        <Path x:Name="path"
                                                              Data="M288.75,232.25 L288.75,240.625 L283,236.625 z"
                                                              Fill="#e0e0e0"
                                                              HorizontalAlignment="Left"
                                                              Height="15"
                                                              Width="15"
                                                              Margin="20,0,0,0"
                                                              Stretch="Fill"
                                                              VerticalAlignment="Center" />
                                                    </Grid>
                                                </Grid>
                                            </ControlTemplate>
                                            <!--日历头右箭头按钮样式模版,这块跟左箭头样式模版没什么区别-->
                                            <ControlTemplate x:Key="NextButtonTemplate"
                                                             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 = "#363636"
                                                               Opacity="1"
                                                               Stretch="Fill" />
                                                    <Grid>
                                                        <Path x:Name="path"
                                                              Data="M282.875,231.875 L282.875,240.375 L288.625,236 z"
                                                              Fill="#e0e0e0"
                                                              HorizontalAlignment="Right"
                                                              Height="15"
                                                              Width="15"
                                                              Margin="0,0,20,0"
                                                              Stretch="Fill"
                                                              VerticalAlignment="Center" />
                                                    </Grid>
                                                </Grid>
                                            </ControlTemplate>
                                            <!--日历头中间年按钮样式模版-->
                                            <ControlTemplate x:Key="HeaderButtonTemplate"
                                                             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="(TextElement.Foreground).(SolidColorBrush.Color)"
                                                                                    Storyboard.TargetName="buttonContent" />
                                                                </Storyboard>
                                                            </VisualState>
                                                            <VisualState x:Name="Disabled">
                                                                <Storyboard>
                                                                    <DoubleAnimation Duration = "0"
                                                                                     To=".5"
                                                                                     Storyboard.TargetProperty="Opacity"
                                                                                     Storyboard.TargetName="buttonContent" />
                                                                </Storyboard>
                                                            </VisualState>
                                                        </VisualStateGroup>
                                                    </VisualStateManager.VisualStateGroups>
                                                    <ContentPresenter x:Name="buttonContent"
                                                                      ContentTemplate="{TemplateBinding ContentTemplate}"
                                                                      Content="{TemplateBinding Content}"
                                                                      TextElement.Foreground="#e0e0e0"
                                                                      HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                                      Margin="1,4,1,9"
                                                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                                </Grid>
                                            </ControlTemplate>
                                        </Grid.Resources>

                                        <Grid.RowDefinitions>
                                            <!--日历头,左箭头,,右箭头-->
                                            <RowDefinition Height = "Auto" />
                                            <!--日历内容, 星期几和具体的日期几号几号-->
                                            <RowDefinition Height = "*" />
                                        </Grid.RowDefinitions >
                                        <Grid.ColumnDefinitions >
                                            <!--左箭头-->
                                            <ColumnDefinition Width="Auto" />
                                            <!---->
                                            <ColumnDefinition Width = "*" />
                                            <!--右箭头-->
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                        <!--,左箭头,,右箭头,整体的背景色-->
                                        <Border Grid.Row="0"
                                                Grid.ColumnSpan= "3"
                                                Background= "#363636" ></Border >
                                        <!--左箭头-->
                                        <Button x:Name= "PART_PreviousButton"
                                                Grid.Column= "0"
                                                Focusable= "False"
                                                HorizontalAlignment= "Left"
                                                Grid.Row= "0"
                                                Template= "{StaticResource PreviousButtonTemplate}" />
                                        <!---->
                                        <Button x:Name= "PART_HeaderButton"
                                                Grid.Column= "1"
                                                FontFamily= "微软雅黑"
                                                Focusable= "False"
                                                FontSize= "26"
                                                HorizontalAlignment= "Center"
                                                Grid.Row= "0"
                                                Template= "{StaticResource HeaderButtonTemplate}"
                                                VerticalAlignment= "Center" />
                                        <!--右箭头-->
                                        <Button x:Name= "PART_NextButton"
                                                Grid.Column= "2"
                                                Focusable= "False"
                                                HorizontalAlignment= "Right"
                                                Grid.Row= "0"
                                                Template= "{StaticResource NextButtonTemplate}" />
                                        <!--日期几号几号内容显示-->
                                        <Border Grid.Row= "1"
                                                Grid.ColumnSpan= "3"
                                                Margin= "0"
                                                BorderBrush= "#cfcfcf"
                                                BorderThickness= "3,0,3,3" >
                                            <Grid x:Name= "PART_MonthView"
                                                  HorizontalAlignment= "Center"
                                                  Visibility= "Visible" >
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width= "*" />
                                                    <ColumnDefinition Width= "*" />
                                                    <ColumnDefinition Width= "*" />
                                                    <ColumnDefinition Width= "*" />
                                                    <ColumnDefinition Width= "*" />
                                                    <ColumnDefinition Width= "*" />
                                                    <ColumnDefinition Width= "*" />
                                                </Grid.ColumnDefinitions>
                                                <Grid.RowDefinitions >
                                                    <RowDefinition Height= "auto" />
                                                    <RowDefinition Height= "*" />
                                                    <RowDefinition Height= "*" />
                                                    <RowDefinition Height= "*" />
                                                    <RowDefinition Height= "*" />
                                                    <RowDefinition Height= "*" />
                                                    <RowDefinition Height= "*" />
                                                </Grid.RowDefinitions >
                                            </Grid >
                                        </Border >

                                        <!--月和年内容显示-->
                                        <Grid x:Name= "PART_YearView"
                                              Grid.ColumnSpan= "3"
                                              HorizontalAlignment= "Center"
                                              Margin= "6,-3,7,6"
                                              Grid.Row= "1"
                                              Visibility= "Hidden"
                                              VerticalAlignment= "Center" >
                                            <Grid.ColumnDefinitions >
                                                <ColumnDefinition Width= "*" />
                                                <ColumnDefinition Width= "*" />
                                                <ColumnDefinition Width= "*" />
                                                <ColumnDefinition Width= "*" />
                                            </Grid.ColumnDefinitions >
                                            <Grid.RowDefinitions >
                                                <RowDefinition Height= "*" />
                                                <RowDefinition Height= "*" />
                                                <RowDefinition Height= "*" />
                                            </Grid.RowDefinitions >
                                        </Grid >
                                    </Grid >
                                </Border >
                            </Border >
                            <!--日历不可用的遮罩层-->
                            <Rectangle x:Name= "PART_DisabledVisual"
                                       Fill= "{StaticResource DisabledColor}"
                                       Opacity= "0"
                                       RadiusY= "2"
                                       RadiusX= "2"
                                       Stretch= "Fill"
                                       Stroke= "{StaticResource DisabledColor}"
                                       StrokeThickness= "1"
                                       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= "CalendarDayButtonStyle1"
               TargetType= "{x:Type CalendarDayButton}" >
            <Setter Property= "Margin"
                    Value= "1" />
            <Setter Property= "MinWidth"
                    Value= "5" />
            <Setter Property= "MinHeight"
                    Value= "5" />
            <Setter Property= "FontSize"
                    Value= "22" />
            <Setter Property= "FontFamily"
                    Value= "微软雅黑" />
            <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= "CommonStates" >
                                    <VisualStateGroup.Transitions >
                                        <VisualTransition GeneratedDuration= "0:0:0.1" />
                                    </VisualStateGroup.Transitions >
                                    <VisualState x:Name= "Normal" />
                                    <!--悬停的颜色动画-->
                                    <VisualState x:Name= "MouseOver" >
                                        <Storyboard >
                                            <DoubleAnimation Duration= "0"
                                                             To= "0.5"
                                                             Storyboard.TargetProperty= "Opacity"
                                                             Storyboard.TargetName= "HighlightBackground" />
                                        </Storyboard>
                                    </VisualState >
                                    <!--按下后动画-->
                                    <VisualState x:Name= "Pressed" >
                                        <Storyboard >
                                            <DoubleAnimation Duration= "0"
                                                             To= "0.5"
                                                             Storyboard.TargetProperty= "Opacity"
                                                             Storyboard.TargetName= "HighlightBackground" />
                                        </Storyboard>
                                    </VisualState >
                                    <!--不可用动画-->
                                    <VisualState x:Name= "Disabled" >
                                        <Storyboard >
                                            <DoubleAnimation Duration= "0"
                                                             To= "0"
                                                             Storyboard.TargetProperty= "Opacity"
                                                             Storyboard.TargetName= "HighlightBackground" />
                                            <DoubleAnimation Duration= "0"
                                                             To= ".35"
                                                             Storyboard.TargetProperty= "Opacity"
                                                             Storyboard.TargetName= "NormalText" />
                                        </Storyboard>
                                    </VisualState >
                                </VisualStateGroup >
                                <VisualStateGroup x:Name= "SelectionStates" >
                                    <VisualStateGroup.Transitions >
                                        <VisualTransition GeneratedDuration= "0" />
                                    </VisualStateGroup.Transitions >
                                    <VisualState x:Name= "Unselected" />
                                    <!--选中某日期的样式-->
                                    <VisualState x:Name= "Selected" >
                                        <Storyboard >
                                            <DoubleAnimation Duration= "0"
                                                             To= ".75"
                                                             Storyboard.TargetProperty= "Opacity"
                                                             Storyboard.TargetName= "SelectedBackground" />
                                            <ColorAnimation Duration= "0"
                                                            To= "white"
                                                            Storyboard.TargetProperty= "(TextElement.Foreground).(SolidColorBrush.Color)"
                                                            Storyboard.TargetName= "NormalText" />
                                        </Storyboard>
                                    </VisualState >
                                </VisualStateGroup >
                                <VisualStateGroup x:Name= "CalendarButtonFocusStates" >
                                    <VisualStateGroup.Transitions >
                                        <VisualTransition GeneratedDuration= "0" />
                                    </VisualStateGroup.Transitions >
                                    <VisualState x:Name= "CalendarButtonFocused" >
                                        <Storyboard >
                                            <ObjectAnimationUsingKeyFrames Duration= "0"
                                                                           Storyboard.TargetProperty= "Visibility"
                                                                           Storyboard.TargetName= "DayButtonFocusVisual" >
                                                <DiscreteObjectKeyFrame KeyTime= "0" >
                                                    <DiscreteObjectKeyFrame.Value >
                                                        <Visibility >Visible</Visibility >
                                                    </DiscreteObjectKeyFrame.Value >
                                                </DiscreteObjectKeyFrame >
                                            </ObjectAnimationUsingKeyFrames >
                                        </Storyboard>
                                    </VisualState >
                                    <VisualState x:Name= "CalendarButtonUnfocused" >
                                        <Storyboard >
                                            <ObjectAnimationUsingKeyFrames Duration= "0"
                                                                           Storyboard.TargetProperty= "Visibility"
                                                                           Storyboard.TargetName= "DayButtonFocusVisual" >
                                                <DiscreteObjectKeyFrame KeyTime= "0" >
                                                    <DiscreteObjectKeyFrame.Value >
                                                        <Visibility >Collapsed</Visibility >
                                                    </DiscreteObjectKeyFrame.Value >
                                                </DiscreteObjectKeyFrame >
                                            </ObjectAnimationUsingKeyFrames >
                                        </Storyboard>
                                    </VisualState >
                                </VisualStateGroup >
                                <VisualStateGroup x:Name= "ActiveStates" >
                                    <VisualStateGroup.Transitions >
                                        <VisualTransition GeneratedDuration= "0" />
                                    </VisualStateGroup.Transitions >
                                    <VisualState x:Name= "Active" />
                                    <VisualState x:Name= "Inactive" >
                                        <Storyboard >
                                            <ColorAnimation Duration= "0"
                                                            To= "#b4b3b3"
                                                            Storyboard.TargetProperty= "(TextElement.Foreground).(SolidColorBrush.Color)"
                                                            Storyboard.TargetName= "NormalText" />
                                        </Storyboard>
                                    </VisualState >
                                </VisualStateGroup >
                                <VisualStateGroup x:Name= "DayStates" >
                                    <VisualStateGroup.Transitions >
                                        <VisualTransition GeneratedDuration= "0" />
                                    </VisualStateGroup.Transitions >
                                    <VisualState x:Name= "RegularDay" />
                                    <!--今天的样式-->
                                    <VisualState x:Name= "Today" >
                                        <Storyboard >
                                            <DoubleAnimation Duration= "0"
                                                             To= "1"
                                                             Storyboard.TargetProperty= "Opacity"
                                                             Storyboard.TargetName= "TodayBackground" />
                                            <ColorAnimation Duration= "0"
                                                            To= "#666666"
                                                            Storyboard.TargetProperty= "(TextElement.Foreground).(SolidColorBrush.Color)"
                                                            Storyboard.TargetName= "NormalText" />

                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty= "Visibility"
                                                                           Storyboard.TargetName= "imgToday" >
                                                <DiscreteObjectKeyFrame KeyTime= "0" >
                                                    <DiscreteObjectKeyFrame.Value >
                                                        <Visibility >Visible</Visibility >
                                                    </DiscreteObjectKeyFrame.Value >
                                                </DiscreteObjectKeyFrame >
                                            </ObjectAnimationUsingKeyFrames >

                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <!--过期日期的-->
                                <VisualStateGroup x:Name= "BlackoutDayStates" >
                                    <VisualStateGroup.Transitions >
                                        <VisualTransition GeneratedDuration= "0" />
                                    </VisualStateGroup.Transitions >
                                    <VisualState x:Name= "NormalDay" />
                                    <VisualState x:Name= "BlackoutDay" >
                                        <Storyboard >
                                            <DoubleAnimation Duration= "0"
                                                             To= ".2"
                                                             Storyboard.TargetProperty= "Opacity"
                                                             Storyboard.TargetName= "Blackout" />
                                        </Storyboard>
                                    </VisualState >
                                </VisualStateGroup >
                            </VisualStateManager.VisualStateGroups >
                            <Border BorderBrush= "#bbbbbb"
                                    BorderThickness= "1" >
                                <Border BorderBrush= "white"
                                        BorderThickness= "2,2,0,0"
                                        Margin= "1,1,0,0" ></Border >
                            </Border >

                            <Rectangle x:Name= "TodayBackground"
                                       Fill= "#c6c6c6"
                                       Opacity= "0"
                                       RadiusY= "1"
                                       RadiusX= "1" />
                            <Rectangle x:Name= "SelectedBackground"
                                       Fill= "#6eafbf"
                                       Opacity= "0"
                                       RadiusY= "1"
                                       RadiusX= "1" />
                            <Border BorderBrush= "{TemplateBinding BorderBrush}"
                                    BorderThickness= "{TemplateBinding BorderThickness}"
                                    Background= "{TemplateBinding Background}" />
                            <Rectangle x:Name= "HighlightBackground"
                                       Fill= "#FFBADDE9"
                                       Opacity= "0"
                                       RadiusY= "1"
                                       RadiusX= "1" />
                            <ContentPresenter x:Name= "NormalText"
                                              TextElement.Foreground= "#666666"
                                              HorizontalAlignment= "{TemplateBinding HorizontalContentAlignment}"
                                              VerticalAlignment= "{TemplateBinding VerticalContentAlignment}" />
                            <Path x:Name= "Blackout"
                                  Data= "M8.1772461,11.029181 L10.433105,11.029181 L11.700684,12.801641 L12.973633,11.029181 L15.191895,11.029181 L12.844727,13.999395 L15.21875,17.060919 L12.962891,17.060919 L11.673828,15.256231 L10.352539,17.060919 L8.1396484,17.060919 L10.519043,14.042364 z"
                                  Fill= "#FF000000"
                                  HorizontalAlignment= "Stretch"
                                  Margin= "3"
                                  Opacity= "0"
                                  RenderTransformOrigin= "0.5,0.5"
                                  Stretch= "Fill"
                                  VerticalAlignment= "Stretch" />
                            <Rectangle x:Name= "DayButtonFocusVisual"
                                       IsHitTestVisible= "false"
                                       RadiusY= "1"
                                       RadiusX= "1"
                                       Stroke= "#FF45D6FA"
                                       Visibility= "Collapsed" />
                            <!--Width= "44"
                                   Height= "34"-->
                            <Image x:Name= "imgToday" 
                                   Source= "../../CommonInMy/Image/秋意图.jpg"
                                   VerticalAlignment= "Top"
                                   HorizontalAlignment= "Left"
                                   Visibility= "Hidden" />
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <TextBlock FontSize="10" Grid.Row="4"  Foreground="DarkGray"  Text="{Binding Converter={StaticResource DayConverter} }">  </TextBlock>
                                  
                            </Grid> 
                        </Grid>
                        
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key= "CalendarButtonStyle1"
               TargetType= "{x:Type CalendarButton}" >
            <Setter Property= "Background"
                    Value= "#FFBADDE9" />
            <Setter Property= "MinWidth"
                    Value= "80" />
            <Setter Property= "MinHeight"
                    Value= "120" />
            <Setter Property= "Margin"
                    Value= "20" />
            <Setter Property= "FontSize"
                    Value= "25" />
            <Setter Property= "HorizontalContentAlignment"
                    Value= "Center" />
            <Setter Property= "VerticalContentAlignment"
                    Value= "Center" />
            <Setter Property= "Template" >
                <Setter.Value >
                    <ControlTemplate TargetType= "{x:Type CalendarButton}" >
                        <Grid >
                            <VisualStateManager.VisualStateGroups >
                                <VisualStateGroup x:Name= "CommonStates" >
                                    <VisualStateGroup.Transitions >
                                        <VisualTransition GeneratedDuration= "0:0:0.1" />
                                    </VisualStateGroup.Transitions >
                                    <VisualState x:Name= "Normal" />
                                    <VisualState x:Name= "MouseOver" >
                                        <Storyboard >
                                            <DoubleAnimation Duration= "0"
                                                             To= ".5"
                                                             Storyboard.TargetProperty= "Opacity"
                                                             Storyboard.TargetName= "Background" />
                                        </Storyboard>
                                    </VisualState >
                                    <VisualState x:Name= "Pressed" >
                                        <Storyboard >
                                            <DoubleAnimation Duration= "0"
                                                             To= ".5"
                                                             Storyboard.TargetProperty= "Opacity"
                                                             Storyboard.TargetName= "Background" />
                                        </Storyboard>
                                    </VisualState >
                                </VisualStateGroup >
                                <VisualStateGroup x:Name= "SelectionStates" >
                                    <VisualStateGroup.Transitions >
                                        <VisualTransition GeneratedDuration= "0" />
                                    </VisualStateGroup.Transitions >
                                    <VisualState x:Name= "Unselected" />
                                    <VisualState x:Name= "Selected" >
                                        <Storyboard >
                                            <DoubleAnimation Duration= "0"
                                                             To= ".75"
                                                             Storyboard.TargetProperty= "Opacity"
                                                             Storyboard.TargetName= "SelectedBackground" />
                                        </Storyboard>
                                    </VisualState >
                                </VisualStateGroup >
                                <VisualStateGroup x:Name= "ActiveStates" >
                                    <VisualStateGroup.Transitions >
                                        <VisualTransition GeneratedDuration= "0" />
                                    </VisualStateGroup.Transitions >
                                    <VisualState x:Name= "Active" />
                                    <VisualState x:Name= "Inactive" >
                                        <Storyboard >
                                            <ColorAnimation Duration= "0"
                                                            To= "#FF777777"
                                                            Storyboard.TargetProperty= "(TextElement.Foreground).(SolidColorBrush.Color)"
                                                            Storyboard.TargetName= "NormalText" />
                                        </Storyboard>
                                    </VisualState >
                                </VisualStateGroup >
                                <VisualStateGroup x:Name= "CalendarButtonFocusStates" >
                                    <VisualStateGroup.Transitions >
                                        <VisualTransition GeneratedDuration= "0" />
                                    </VisualStateGroup.Transitions >
                                    <VisualState x:Name= "CalendarButtonFocused" >
                                        <Storyboard >
                                            <ObjectAnimationUsingKeyFrames Duration= "0"
                                                                           Storyboard.TargetProperty= "Visibility"
                                                                           Storyboard.TargetName= "CalendarButtonFocusVisual" >
                                                <DiscreteObjectKeyFrame KeyTime= "0" >
                                                    <DiscreteObjectKeyFrame.Value >
                                                        <Visibility >Visible</Visibility >
                                                    </DiscreteObjectKeyFrame.Value >
                                                </DiscreteObjectKeyFrame >
                                            </ObjectAnimationUsingKeyFrames >
                                        </Storyboard>
                                    </VisualState >
                                    <VisualState x:Name= "CalendarButtonUnfocused" >
                                        <Storyboard >
                                            <ObjectAnimationUsingKeyFrames Duration= "0"
                                                                           Storyboard.TargetProperty= "Visibility"
                                                                           Storyboard.TargetName= "CalendarButtonFocusVisual" >
                                                <DiscreteObjectKeyFrame KeyTime= "0" >
                                                    <DiscreteObjectKeyFrame.Value >
                                                        <Visibility >Collapsed</Visibility >
                                                    </DiscreteObjectKeyFrame.Value >
                                                </DiscreteObjectKeyFrame >
                                            </ObjectAnimationUsingKeyFrames >
                                        </Storyboard>
                                    </VisualState >
                                </VisualStateGroup >
                            </VisualStateManager.VisualStateGroups >
                            <Rectangle x:Name= "SelectedBackground"
                                       Fill= "{TemplateBinding Background}"
                                       Opacity= "0"
                                       RadiusY= "1"
                                       RadiusX= "1" />
                            <Rectangle x:Name= "Background"
                                       Fill= "{TemplateBinding Background}"
                                       Opacity= "0"
                                       RadiusY= "1"
                                       RadiusX= "1" />
                            <ContentPresenter x:Name= "NormalText"
                                              TextElement.Foreground= "#FF333333"
                                              HorizontalAlignment= "{TemplateBinding HorizontalContentAlignment}"
                                              Margin= "1,0,1,1"
                                              VerticalAlignment= "{TemplateBinding VerticalContentAlignment}" />
                            <Rectangle x:Name= "CalendarButtonFocusVisual"
                                       IsHitTestVisible= "false"
                                       RadiusY= "1"
                                       RadiusX= "1"
                                       Stroke= "#FF45D6FA"
                                       Visibility= "Collapsed" />
                        </Grid >
                        <ControlTemplate.Triggers >
                            <Trigger Property= "IsFocused"
                                     Value= "True" >
                                <Setter Property= "Visibility"
                                        TargetName= "CalendarButtonFocusVisual"
                                        Value= "Visible" />
                            </Trigger >
                        </ControlTemplate.Triggers >
                    </ControlTemplate >
                </Setter.Value >
            </Setter >
        </Style >
    </UserControl.Resources >
    <Grid>
        <Calendar Style= "{DynamicResource CalendarStyle1}"
                  CalendarItemStyle= "{DynamicResource CalendarItemStyle1}"
                  CalendarDayButtonStyle= "{DynamicResource CalendarDayButtonStyle1}"
                  CalendarButtonStyle= "{DynamicResource CalendarButtonStyle1}">

        </Calendar>
    </Grid>

其中绝大部分功能都是写样式:因为没有绑定的 itemsource 功能,加入一个textblock 来展示操作:

<Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <TextBlock FontSize="10" Grid.Row="4"  Foreground="DarkGray"  Text="{Binding Converter={StaticResource DayConverter} }">  </TextBlock>
              
        </Grid>  

只能够用转换器来操作,因为这converter 调用的时候是自动value传入的是 当前 日期模式 ‘2024-10-24 00:00:00’ 需要再转换器 先 转换成日期操作,然后进入数据库查询当日数据 然后返回 需要字段。
在这里插入图片描述
所以转换的方法应该这么写:

  public  class DayConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                DateTime test = (DateTime)value;
                string date = test.ToString("yyyy-MM-dd");
                string wheres = "";
                if (GModel.User.SimiaoId!=1 )
                {
                    wheres += $" and SiniaoId = {GModel.User.SimiaoId} ";
                }
                wheres += $" and ThisDay = '{date}' ";
                string Outstr = new DAL.DALFahuiInfo().QueryShowByCalender(wheres);
                return Outstr;
            }
            return string.Empty;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
        #endregion


    }

其中关于日期的sql操作是这样的 新增一个日期列,然后比对日期即可

 /// <summary>
        /// 显示当前日期数据
        /// </summary>
        /// <param name="wheres">wheres条件</param>
        /// <returns></returns>
        public string  QueryShowByCalender(string Wheres)
        { 
            string sql = $@"SELECT b.FahuiName   FROM  ( select a.* from (select   FahuiName ,CONVERT(varchar(100),SetStartDate, 23) as  ThisDay  from [FahuiInfo]) a     where 1=1 {Wheres}) b";
             IEnumerable<string> ThisFanhuiNames =  DapperDbHelper.Query<string>(sql);
            string OutStr = "";
            if (ThisFanhuiNames != null)
            {
                OutStr = string.Join(",",ThisFanhuiNames);
            }
            return OutStr;
        }

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/905515.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

园区网典型技术应用

工厂、政府机关、商场、写字楼、校园、公园等&#xff0c;这些场所内为了实现数据互通而搭建的网络都可以称之为园区网 1. 园区网络架构与常见技术概述 某高校校园网络采用三层架构&#xff0c;核心层和汇聚层各有其明确的职责&#xff1a; 核心层&#xff1a;部署两台核心交…

计算机考研,选择西安交通大学还是哈工大?

C哥专业提供——计软考研院校选择分析专业课备考指南规划 经过全面分析&#xff0c;2025年考研西安交通大学和哈尔滨工业大学计算机专业的报考难度对比如下&#xff1a; 西安交通大学计算机专业 > 哈尔滨工业大学计算机专业 对于想要报考985高校计算机专业但核心目标是优…

3D游戏阴影技术综合指南

在维姆文德斯 (Wim Wenders) 的优秀作品《完美的日子》 (Perfect Days) 的结尾&#xff0c;男主角平山 (Hirayama) 在桥下喝啤酒&#xff0c;因为他看到一个商人在追求他的暗恋对象。突然&#xff0c;商人在桥下加入了他。事实证明&#xff0c;事情并没有那么简单&#xff0c;但…

Unity 2D寻路导航 NavMeshPlus解决方案

插件的github主页 h8man/NavMeshPlus: Unity NavMesh 2D Pathfinding 这个插件是基于新版3D寻路导航制作的&#xff0c;所以你可能需要看一下这篇文章 新旧Navmash 寻路导航组件对比 附使用案例与实用教程链接-CSDN博客 这行代码agent.updateUpAxis false 一定要为代理单位…

K8s企业应用之容器化迁移

#作者&#xff1a;曹付江 K8s企业应用之容器化迁移 Kubernetes&#xff08;K8s&#xff09;中的企业应用容器化迁移是一个复杂但重要的过程&#xff0c;平滑的迁移应用&#xff0c;可以让开发、运维、测试人员循序渐进的学习和掌握Kubernetes&#xff0c;通常包括以下步骤&am…

Flash的语音ic型号有哪些?

深圳唯创知音电子有限公司在语音技术领域具有深厚的积累&#xff0c;其Flash语音IC产品凭借高性能和广泛的应用领域&#xff0c;在市场上占据了一席之地。以下是对该公司Flash语音IC产品的详细介绍&#xff1a; 一、产品概述 Flash语音IC是一种采用Flash存储技术的语音芯片&…

vscode摸鱼学习插件开发

不知道大家在摸鱼的时候&#xff0c;会不会想要学习&#xff1f; 或者有没有考公人&#xff0c;下班要学习的&#xff1f; 上班时间摸鱼&#xff0c;下班时间不够学习&#xff1f; 为此&#xff0c;我决定开发一个vscode插件&#xff0c;来刷粉笔题 粉笔插件名称&#xff1a;…

PPT制作新选择:本地部署PPTist结合内网穿透实现实时协作和远程使用

文章目录 前言1. 本地安装PPTist2. PPTist 使用介绍3. 安装Cpolar内网穿透4. 配置公网地址5. 配置固定公网地址 &#x1f4a1; 推荐 前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。【点击跳转到网站】 前…

文件上传知识梳理:原理、工具、绕过、利用与防御

文章简介&#xff1a; 本文全面梳理了文件上传相关知识&#xff0c;包括文件上传漏洞的原理及危害&#xff0c;介绍了 Webshell 相关工具&#xff08;如冰蝎、哥斯拉、蚁剑&#xff09;&#xff0c;详细阐述了文件上传绕过检测的多种方法&#xff08;前端检测、服务端检测的各…

SpringMvc参数传递

首先对于post请求汉字乱码需要进行过滤器配置 普通参数传递 直接传递 客户端传递的属性名与我的bean中的函数参数名相同 映射传递RequestParam("XXX") 在我们方法参数中定义一个与客户端属性名一致 并绑定参数 POJO实体类传递 嵌套POJO传递 数组likes参数传递…

sqoop Oracle to hive出现 Error Msg = ORA-00933: SQL 命令未正确结束

原sqoop脚本&#xff1a; sqoop import \ --connect "jdbc:oracle:thin://10.82.88.223:61521/LZY2" \ --username LZSHARE \ --password LZ^share$5105 \ --driver oracle.jdbc.driver.OracleDriver \ --query "SELECT TO_NUMBER(TO_CHAR(GCRQ, YYYY)) AS gcr…

Spring Boot + Vue:打造高效图书借阅管理平台

作者介绍&#xff1a;✌️大厂全栈码农|毕设实战开发&#xff0c;专注于大学生项目实战开发、讲解和毕业答疑辅导。 &#x1f345;获取源码联系方式请查看文末&#x1f345; 推荐订阅精彩专栏 &#x1f447;&#x1f3fb; 避免错过下次更新 Springboot项目精选实战案例 更多项目…

STM32F103C8T6学习笔记1--新建工程模板

1、简介 STM32是一系列由STMicroelectronics&#xff08;瑞士意法半导体&#xff09;公司设计和生产的32位微控制器产品线。这些微控制器基于ARM Cortex-M内核&#xff0c;并具有高性能、低功耗和多种外设接口的特点。STM32处理器被广泛应用于各种嵌入式系统领域&#xff0c;包…

Java日志脱敏(二)——fastjson Filter + 注解 + 工具类实现

背景简介 日志脱敏 是常见的安全需求&#xff0c;最近公司也需要将这一块内容进行推进。看了一圈网上的案例&#xff0c;很少有既轻量又好用的轮子可以让我直接使用。我一直是反对过度设计的&#xff0c;而同样我认为轮子就应该是可以让人拿去直接用的。所以我准备分享两篇博客…

篡改猴 (Tampermonkey) 安装与使用

一、下载篡改猴 (Tampermonkey) 步骤1---官网&#xff1a;篡改猴 - Microsoft Edge Addons

无人机之感知避让技术篇

无人机的感知避让技术是无人机安全飞行的重要保障&#xff0c;它依赖于多种传感器和算法来实现对周围环境的感知和判断。 一、主要技术类型 视觉避障 原理&#xff1a;通过安装在无人机上的摄像头捕捉周围环境的图像&#xff0c;利用计算机视觉技术对图像进行处理和分析&…

动态规划路径问题(不同路径 不同路径2 珠宝的最大价值 下降路径最小和 最小路径和)

本期题型&#xff1a; 1. 不同路径. - 力扣&#xff08;LeetCode&#xff09; 2. 不同路径2. - 力扣&#xff08;LeetCode&#xff09; 3. 珠宝的最大价值 . - 力扣&#xff08;LeetCode&#xff09; 4. 下降路径最小和. - 力扣&#xff08;LeetCode&#xff09; …

ARM base instruction -- bfxil

Bitfield Extract and Insert Low copies a bitfield of <width> bits starting from bit position <lsb> in the source register to the least significant bits of the destination register, leaving the other destination bits unchanged. 位域提取并插入低位…

1.探索WebSocket:实时网络的心跳!

序言 你可能听说过"WebSokcet"这个词&#xff0c;感觉它好像很高深&#xff0c;但其实它是一个超级酷的小工具&#xff0c;让我们在Web应用里实现实时通信。想象一下&#xff0c;你可以像聊天一样&#xff0c;在浏览器和服务器之间来回“畅聊“&#xff0c;没有延迟…

springboot 修复 Spring Framework 特定条件下目录遍历漏洞(CVE-2024-38819)

刚解决Spring Framework 特定条件下目录遍历漏洞&#xff08;CVE-2024-38816&#xff09;没几天&#xff0c;又来一个新的&#xff0c;真是哭笑不得啊。 springboot 修复 Spring Framework 特定条件下目录遍历漏洞&#xff08;CVE-2024-38816&#xff09;https://blog.csdn.ne…