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.mzph.cn/diannao/58988.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Qt第三课 ----------输入类的控件属性

作者前言 &#x1f382; ✨✨✨✨✨✨&#x1f367;&#x1f367;&#x1f367;&#x1f367;&#x1f367;&#x1f367;&#x1f367;&#x1f382; ​&#x1f382; 作者介绍&#xff1a; &#x1f382;&#x1f382; &#x1f382; &#x1f389;&#x1f389;&#x1f389…

LabVIEW 离心泵机组故障诊断系统

开发了一套基于LabVIEW图形化编程语言设计的离心泵机组故障诊断系统。系统利用先进的数据采集技术和故障诊断方法&#xff0c;通过远程在线监测与分析&#xff0c;有效提升了离心泵的预测性维护能力&#xff0c;保证了石油化工生产的连续性和安全性。 项目背景及意义 离心泵作…

typescript的简介

简介 tsc npm install -g typescripttsc -v作用 检查类型和语法错误&#xff0c;提前纠错 ts的类型 如何穿件带有ts的vue工程 作用 常见类型 用法 编写一个ts文件 let username:string "John";let age:number 25;let isUpdated:boolean true;let data:any &q…

WPF+MVVM案例实战(二十)- 制作一个雷达辐射效果的按钮

文章目录 1、案例效果2、文件创建与代码实现1、创建文件2、图标资源文件3、源代码获取1、案例效果 2、文件创建与代码实现 1、创建文件 打开 Wpf_Examples 项目,在 Views 文件夹下创建窗体界面 RadarEffactWindow.xaml 。代码功能分两个部分完成,一个是样式,一个是动画。页…

​Java面试经典 150 题.P13. 罗马数字转整数(012)​

本题来自&#xff1a;力扣-面试经典 150 题 面试经典 150 题 - 学习计划 - 力扣&#xff08;LeetCode&#xff09;全球极客挚爱的技术成长平台https://leetcode.cn/studyplan/top-interview-150/ 题解&#xff1a; class Solution {public int romanToInt(String s) {int sum…

一键AI换衣-可图AI试衣

我们的真的实现了穿衣自由了吗&#xff1f;上传一张人物图片和衣服的图片&#xff0c;就能实现一键换衣。 这就是可图AI试衣项目 魔塔地址&#xff1a;https://www.modelscope.cn/studio ... lors-Virtual-Try-On 参考&#xff1a; 一键AI换衣-可图AI试衣 https://www.jinsh…

Java项目实战II基于Spring Boot的个人云盘管理系统设计与实现(开发文档+数据库+源码)

目录 一、前言 二、技术介绍 三、系统实现 四、文档参考 五、核心代码 六、源码获取 全栈码农以及毕业设计实战开发&#xff0c;CSDN平台Java领域新星创作者&#xff0c;专注于大学生项目实战开发、讲解和毕业答疑辅导。 一、前言 基于Spring Boot的个人云盘管理系统设计…

奇瑞汽车:降阶模型在新能源汽车热管理仿真上的应用

随着新能源汽车的发展&#xff0c;对仿真技术的要求也越来越高。那么奇瑞汽车利用降阶模型在新能源汽车热管理仿真上做了哪些应用呢&#xff1f;本次内容主要从四个方面展开介绍&#xff1a; 1、 奇瑞汽车简介&#xff1b; 2、 热管理降阶模型开发的背景&#xff1b; 3、 高低…

ctf文件上传题小总结与记录

解题思路&#xff1a;先看中间件&#xff0c;文件上传点&#xff08;字典扫描&#xff0c;会员中心&#xff09;&#xff0c;绕过/验证&#xff08;黑名单&#xff0c;白名单&#xff09;&#xff0c;解析漏洞&#xff0c;cms&#xff0c;编辑器&#xff0c;最新cve 文件上传漏…

nginx上传文件超过限制大小、响应超时、反向代理请求超时等问题解决

1、文件大小超过限制 相关配置&#xff1a; client_max_body_size&#xff1a; Syntax:client_max_body_size size;Default:client_max_body_size 1m;Context:http, server, location 2、连接超时: proxy_read_timeout&#xff1a; Syntax:proxy_read_timeout time;Default…

00-开发环境 MPLAB IDE 配置

MPLAB IDE V8.83 File 菜单简介 New (CtrlN)&#xff1a; 创建一个新文件&#xff0c;用于编写新的代码。 Add New File to Project...&#xff1a; 将新文件添加到当前项目中。 Open... (CtrlO)&#xff1a; 打开现有文件。 Close (CtrlE)&#xff1a; 关闭当前打开的文件。 …

基于BP神经网络的手写体数字图像识别

基于BP神经网络的手写体数字图像识别 摘要 在信息化飞速发展的时代&#xff0c;光学字符识别是一个重要的信息录入与信息转化的手段&#xff0c;其中手写体数字的识别有着广泛地应用&#xff0c;如&#xff1a;邮政编码、统计报表、银行票据等等&#xff0c;因其广泛地应用范围…

鸿蒙进阶篇-Swiper组件的使用

“在科技的浪潮中&#xff0c;鸿蒙操作系统宛如一颗璀璨的新星&#xff0c;引领着创新的方向。作为鸿蒙开天组&#xff0c;今天我们将一同踏上鸿蒙基础的探索之旅&#xff0c;为您揭开这一神奇系统的神秘面纱。” 各位小伙伴们我们又见面了,我就是鸿蒙开天组,下面让我们进入今…

Ubuntu删除docker

文章目录 安装依赖1.安装操作系统&#xff1a;2.CPU支持 安装docker1.查看系统版本2.执行卸载 安装依赖 1.安装操作系统&#xff1a; 高于 Ubuntu 20.04(LTS) 版本 2.CPU支持 ARM和X86_64 安装docker 1.查看系统版本 cat /etc/*releas*uname -a2.执行卸载 检查本地dock…

【机器学习】23. 聚类-GMM: Gaussian Mixture Model

1. 定义和假设 定义&#xff1a;probabilistic clustering&#xff08;model-base&#xff09; 假设&#xff1a;数据服从正态分布 2. 算法内容 我们假设数据是由k个高斯&#xff08;正态&#xff09;分布混合生成的。每个分布有2个参数&#xff1a;μ和σ。 一个分布对应一…

Node.js:Express 服务 路由

Node.js&#xff1a;Express 服务 & 路由 创建服务处理请求req对象 静态资源托管托管多个资源挂载路径前缀 路由模块化 Express是Node.js上的一个第三方框架&#xff0c;可以快速开发一个web框架。本质是一个包&#xff0c;可以通过npm直接下载。 创建服务 Express创建一…

TensorRT-LLM的k8s弹性伸缩部署方案

Scaling LLMs with NVIDIA Triton and NVIDIA TensorRT-LLM Using Kubernetes | NVIDIA Technical Blog 一共涉及4个k8s组件&#xff1a; 1. Deployment&#xff1a;跑起来N个pod&#xff1b;指定NVIDIA官方的triton&trt-llm的docker image&#xff0c;指定好model放在哪个…

6.0、静态路由

路由器最主要的功能就是转发数据包。路由器转发数据包时需要查找路由表&#xff08;你可以理解为地图&#xff09;&#xff0c;管理员可以直接手动配置路由表&#xff0c;这就是静态路由。 1.什么是路由&#xff1f; 在网络世界中&#xff0c;路由是指数据包在网络中的传输路…

4. 类和对象(下)

1. 初始化列表 • 之前我们实现构造函数时&#xff0c;初始化成员变量主要使⽤函数体内赋值&#xff0c;构造函数初始化还有⼀种⽅ 式&#xff0c;就是初始化列表&#xff0c;初始化列表的使⽤⽅式是以⼀个冒号开始&#xff0c;接着是⼀个以逗号分隔的数据成 员列表&#xff0c…

AI驱动的医疗创新:信息抽取与知识图谱在临床应用中的转变

一、思通数科平台支持多种输入格式&#xff0c;如电子病历、临床数据和医学文献等&#xff0c;并能将这些信息快速转换为结构化数据&#xff0c;包括自动360度不同角度的旋转识别&#xff0c;提升数据的可操作性和可检索性。通过我们的解决方案&#xff0c;医疗机构能够有效整合…