Home>

I'm a beginner who recently started WPF (C #).

I'm trying to change the day of the week text color using wpfcalendar but it doesn't work.

A memorandum of a motivated engineer
https://iyemon018.hatenablog.com/entry/2016/05/10/231206
I tried while watching, but is it a dictionary? Because I am using
Not the style setting in the xaml file
I'm in trouble because I don't know how to look at it.

The contents that we want to realize are as follows. (I would appreciate it if you could point out if the recognition is incorrect.)

-Set the style with one xaml file.
・ I want to display only the day of the week in light blue.
・ I want to keep the CS file simple without using it as much as possible.

Could you tell me?

  • Answer # 1

    14th lineThat's it.

    <Window
     x: Class = "Questions304819.MainWindow"
     xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
     SizeToContent = "WidthAndHeight"><Window.Resources><Style x: Key = "CalendarItemStyle1" 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 = "SkyBlue" FontWeight = "Bold" FontSize = "9.5" FontFamily = "Verdana" HorizontalAlignment = "Center" Margin = "0,6,0,6" Text = "{Binding}" VerticalAlignment = "Center" />    <!-↑ Here->   </DataTemplate>  </ControlTemplate.Resources>  <Grid x: Name = "PART_Root">   <Grid.Resources>    <SolidColorBrush x: Key = "DisabledColor" Color = "# A5FFFFFF" />   </Grid.Resources>   <VisualStateManager.VisualStateGroups>    <VisualStateGroup x: Name = "CommonStates">     <VisualState x: Name = "Normal" />     <VisualState x: Name = "Disabled">      <Storyboard>       <DoubleAnimation Duration = "0" To = "1" Storyboard.TargetProperty = "Opacity" Storyboard.TargetName = "PART_DisabledVisual" />      </Storyboard>     </VisualState>    </VisualStateGroup>   </VisualStateManager.VisualStateGroups>   <Border BorderBrush = "{TemplateBinding BorderBrush}" BorderThickness = "{TemplateBinding BorderThickness}" Background = "{TemplateBinding Background}" CornerRadius = "1">    <Border Border Brush = "# FFFFFFFF" BorderThickness = "2" CornerRadius = "1">     <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 = "# 11E5EBF1" Opacity = "1" Stretch = "Fill" />         <Grid>          <Path x: Name = "path" Data = "M288.75,232.25 L288.75,240.625 L283,236.625 z" Fill = "# FF333333" HorizontalAlignment = "Left" Height = "10" Margin = "14,-6,0,0" "Stretch =" Fill "VerticalAlignment =" Center "Width =" 6 "/>         </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 = "# 11E5EBF1" Opacity = "1" Stretch = "Fill" />         <Grid>          <Path x: Name = "path" Data = "M282.875,231.875 L282.875,240.375 L288.625,236 z" Fill = "# FF333333" HorizontalAlignment = "Right" Height = "10" Margin = "0,-6,14,0" "Stretch =" Fill "VerticalAlignment =" Center "Width =" 6 "/>         </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 = "# FF333333" HorizontalAlignment = "{TemplateBinding HorizontalContentAlignment}" Margin = "1,4,1, 9 "VerticalAlignment =" {TemplateBinding VerticalContentAlignment} "/>        </Grid>       </ControlTemplate>      </Grid.Resources>      <Grid.ColumnDefinitions>       <ColumnDefinition Width = "Auto" />       <ColumnDefinition Width = "Auto" />       <ColumnDefinition Width = "Auto" />      </Grid.ColumnDefinitions>      <Grid.RowDefinitions>       <RowDefinition Height = "Auto" />       <RowDefinition Height = "*" />      </Grid.RowDefinitions>      <Button x: Name = "PART_PreviousButton" Grid.Column = "0" Focusable = "False" HorizontalAlignment = "Left" Height = "20" Grid.Row = "0" Template = "{StaticResource PreviousButtonTemplate}" Width = "28" "/>      <Button x: Name = "PART_HeaderButton" Grid.Column = "1" FontWeight = "Bold" Focusable = "False" FontSize = "10.5" HorizontalAlignment = "Center" Grid.Row = "0" Template = "{StaticResource HeaderButtonTemplate}" "Vertical Alignment =" Center "/>      <Button x: Name = "PART_NextButton" Grid.Column = "2" Focusable = "False" HorizontalAlignment = "Right" Height = "20" Grid.Row = "0" Template = "{StaticResource NextButtonTemplate}" Width = "28" "/>      <Grid x: Name = "PART_MonthView" Grid.ColumnSpan = "3" HorizontalAlignment = "Center" Margin = "6, -1,6,6" Grid.Row = "1" Visibility = "Visible">       <Grid.ColumnDefinitions>        <ColumnDefinition Width = "Auto" />        <ColumnDefinition Width = "Auto" />        <ColumnDefinition Width = "Auto" />        <ColumnDefinition Width = "Auto" />        <ColumnDefinition Width = "Auto" />        <ColumnDefinition Width = "Auto" />        <ColumnDefinition Width = "Auto" />       </Grid.ColumnDefinitions>       <Grid.RowDefinitions>        <RowDefinition Height = "Auto" />        <RowDefinition Height = "Auto" />        <RowDefinition Height = "Auto" />        <RowDefinition Height = "Auto" />        <RowDefinition Height = "Auto" />        <RowDefinition Height = "Auto" />        <RowDefinition Height = "Auto" />       </Grid.RowDefinitions>      </Grid>      <Grid x: Name = "PART_YearView" Grid.ColumnSpan = "3" HorizontalAlignment = "Center" Margin = "6, -3,7,6" Grid.Row = "1" Visibility = "Hidden">       <Grid.ColumnDefinitions>        <ColumnDefinition Width = "Auto" /><ColumnDefinition Width = "Auto" />        <ColumnDefinition Width = "Auto" />        <ColumnDefinition Width = "Auto" />       </Grid.ColumnDefinitions>       <Grid.RowDefinitions>        <RowDefinition Height = "Auto" />        <RowDefinition Height = "Auto" />        <RowDefinition Height = "Auto" />       </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></Window.Resources><StackPanel Orientation = "Horizontal"><Calendar x: Name = "custom" CalendarItemStyle = "{DynamicResource CalendarItemStyle1}" /><Calendar x: Name = "normal" /></StackPanel></Window>

  • Answer # 2

    dictionary? Is that a resource dictionary?
    It can also be described as a window resource in the main screen XAML.

    <Window><Window.Resources>    <!-Write here-></Window.Resources></Window>

    I think that it will work even if it is described in this, so that xaml will be one, but is it useless?