WPF Calendar 修改星期几显示内容
<CalendarConverters:CalendarItemConverter x:Key="CalendarItemConverter"/> <Style x:Key="CalendarItemStyle" TargetType="{x:Type CalendarItem}"> <Setter Property="Margin" Value="0,3,0,3" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type CalendarItem}"> <ControlTemplate.Resources> <DataTemplate x:Key="{x:Static CalendarItem.DayTitleTemplateResourceKey}"> <TextBlock Foreground="#FF333333" FontWeight="Bold" FontSize="9.5" FontFamily="Verdana" Margin="0,6,0,6" Text="{Binding Converter={StaticResource CalendarItemConverter}}" HorizontalAlignment="Center" VerticalAlignment="Center"/> </DataTemplate> </ControlTemplate.Resources> </ControlTemplate> </Setter.Value> </Setter> </Style>
public class CalendarItemConverter : IValueConverter { /// <summary> /// /// </summary> /// <param name="value"></param> /// <param name="targetType"></param> /// <param name="parameter"></param> /// <param name="culture"></param> /// <returns></returns> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is string realValue) { switch (realValue) { case "一": return "Ⅰ"; case "二": return "Ⅱ"; case "三": return "Ⅲ"; case "四": return "Ⅳ"; case "五": return "Ⅴ"; case "六": return "休"; case "日": return "假"; } } return value; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } }