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 Memberspublic 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;}

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

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

TOEIC 词汇专题:旅游计划篇

TOEIC 词汇专题&#xff1a;旅游计划篇 制定旅行计划时&#xff0c;尤其是跨国旅游&#xff0c;会涉及到很多独特的英语词汇。以下是与“旅游计划”相关的托业词汇&#xff0c;帮助你更加自如地规划行程。 1. 旅行服务和优惠 出发前了解一下与服务和优惠相关的常用词汇&#…

Java集合框架面试指南

Java集合框架面试指南 文章目录 Java集合框架面试指南ArrayList特点&#xff1a;LinkedList特点&#xff1a;ArrayDeque特点&#xff1a;PriorityQueue特点&#xff1a;HashMap特点&#xff1a;HashSet特点&#xff1a;LinkedHashMap特点LinkedHashMap经典用法 TreeMap特点Conc…

QEMU学习之路(4)— Xilinx开源项目systemctlm-cosim-demo安装与使用

QEMU学习之路&#xff08;4&#xff09;— Xilinx开源项目systemctlm-cosim-demo安装与使用 一、前言 项目说明&#xff1a;https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/862421112/Co-simulation 操作系统&#xff1a;Ubuntu 20.04.6 LTS gcc版本&#xff1a;9.4…

【Java知识】高性能网络应用框架Netty应知应会

文章目录 概述线程模型IO模型代码示例服务端代码示例客户端代码示例代码说明&#xff1a; 自定义协议实现自定义协议格式自定义编码器&#xff08;Encoder&#xff09;自定义解码器&#xff08;Decoder&#xff09;业务处理器&#xff08;Handler&#xff09;在Netty服务器管道…

AUTOSAR 规范中的设计模式:传感器执行器模式

在 AUTOSAR Adaptive Platform (AP) 规范中,传感器执行器模式是一种典型的设计模式,主要用于实时控制系统中,用来实现传感器数据的获取和执行器指令的发送。该模式通过分离传感器和执行器的实现,使其独立运行并且能够通过某种通信机制进行数据交换,以确保数据的实时性和系…

Linux:编辑器Vim和Makefile

✨✨所属专栏&#xff1a;Linux✨✨ ✨✨作者主页&#xff1a;嶔某✨✨ vim的三种常用模式 分别是命令模式&#xff08;command mode&#xff09;、插入模式&#xff08;Insert mode&#xff09;和底行模式&#xff08;last line mode&#xff09; 各模式的功能区分如下&…

【Linux】【进程控制】API汇总整理

进程控制是操作系统中一个非常重要的概念&#xff0c;它涉及到创建、管理和终止进程的能力。进程控制包括一系列操作&#xff0c;如创建新进程、等待进程结束、发送信号给进程等。下面是进程控制中一些常见的操作及其相关API&#xff1a; 进程控制概述 进程控制是指操作系统提…

HTML练习题:彼岸的花(web)

展示效果: 代码: <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>彼岸の花</title><style…

【安全性分析】正式安全分析与非正式安全分析

安全性分析-系列文章目录 第一章 【安全性分析】正式安全分析与非正式安全分析 第二章 【安全性分析】BAN逻辑 (BAN Logic) 文章目录 安全性分析-系列文章目录前言一、正式安全分析1. 理想化模型(如随机预言机模型)2. 标准模型(Standard Model)3. 形式化验证4. 数学证明二…

HTML小阶段二维表和思维导图

下面是对标签、元素、属性的对比二维表&#xff0c;通过对比3w1h&#xff08;what是什么、where用在哪、why为什么要用、how如何用&#xff09;来学习区分学习标签、元素、属性 标签 元素 属性 what &#xff08;Tags&#xff09;标签是用来标记内容块或标明元素内容意义 …

NIO 核心知识总结

在传统的 Java I/O 模型&#xff08;BIO&#xff09;中&#xff0c;I/O 操作是以阻塞的方式进行的。也就是说&#xff0c;当一个线程执行一个 I/O 操作时&#xff0c;它会被阻塞直到操作完成。这种阻塞模型在处理多个并发连接时可能会导致性能瓶颈&#xff0c;因为需要为每个连…

助力风力发电风机设备智能化巡检,基于YOLOv7全系列【tiny/l/x】参数模型开发构建无人机巡检场景下风机叶片缺陷问题智能化检测预警模型

在全球能源转型的大潮中&#xff0c;清洁环境能源的发展已成为各国关注的焦点。风力发电作为其中的佼佼者&#xff0c;以其可再生、无污染的特点&#xff0c;受到了广泛的青睐。然而&#xff0c;风力发电设施大多建于人迹罕至的地区&#xff0c;设备庞大且复杂&#xff0c;其维…

Apache POI(java操作Miscrosoft Office)

Apache POI 1.1 介绍 Apache POI 是一个处理Miscrosoft Office各种文件格式的开源项目。简单来说就是&#xff0c;我们可以使用 POI 在 Java 程序中对Miscrosoft Office各种文件进行读写操作。 一般情况下&#xff0c;POI 都是用于操作 Excel 文件。 Apache POI 的应用场景&a…

C++ | Leetcode C++题解之第537题复数乘法

题目&#xff1a; 题解&#xff1a; class Solution { public:string complexNumberMultiply(string num1, string num2) {regex re("\\|i"); vector<string> complex1(sregex_token_iterator(num1.begin(), num1.end(), re, -1), std::sregex_token_iterator…

Java ==> String类(字符串)

文章目录 一、认识String类1、创建String对象2、不可变的String3、字符串常量池 二、字符串常用操作1、字符串比较1.1 用“”比较1.2 用equals()方法比较1.3用compareTo()方法进行比较 2、获取字符串长度3、字符串查找4、字符串转换4.1valueOf()数值转换为字符串4.2字母大小写转…

Qt中的Model与View 4:QStandardItemModel与QTableView

目录 QStandardItemModel API QTableView 导航 视觉外观 坐标系统 API 样例&#xff1a;解析一个表格txt文件 QStandardItemModel QStandardItemModel 可用作标准 Qt 数据类型的存储库。它是模型/视图类之一&#xff0c;是 Qt 模型/视图框架的一部分。它提供了一种基于…

【SpringMVC】传递json,获取url参数,上传文件

【传递json数据】 【json概念】 一种轻量级数据交互格式&#xff0c;有自己的格式和语法&#xff0c;使用文本表示一个对象或数组的信息&#xff0c;其本质上是字符串&#xff0c;负责在不同的语言中数据传递与交换 json数据以字符串的形式体现 【json字符串与Java对象互转…

Java JUC(四) 自定义线程池实现与原理分析

目录 一. 阻塞队列 BlockingQue 二. 拒绝策略 RejectPolicy 三. 线程池 ThreadPool 四. 模拟运行 在 Java基础&#xff08;二&#xff09; 多线程编程 中&#xff0c;我们简单介绍了线程池 ThreadPoolExecutor 的核心概念与基本使用。在本文中&#xff0c;我们将基于前面学…

go-logger v0.27.0 - 并发性能为官方库 10 倍

go-logger是一个高性能的 golang 日志库&#xff0c;旨在提供快速、轻量级的日志记录功能 Github 使用文档 v0.27.0 更新内容 优化内存分配优化写数据性能增加日志属性自定义函数增加各个日志级别格式化打印函数 说明 性能优化是该版本最重要的更新内容。性能优化的结果&…

【华为HCIP实战课程31(完整版)】中间到中间系统协议IS-IS路由汇总详解,网络工程师

一、IS-IS的汇总 1、可以有效减少在LSP中发布的路由条目,减小对系统资源的占用。 2、会减少LSP报文的扩散,接收到该LSP报文的其他设备路由表中只会出现一条聚合路由。 3、可以避免网络中的路由震荡,提高了网络的稳定性。 4、被聚合的路由可以是IS-IS路由,也可以是被引入…