カレンダーの日付の色を変えたいです。
CalendarのCalendarDayButtonStyleに対して以下のようなスタイルをxamlで定義したいのですが、うまくいかないです。
ご教授ください。
lang
1<Style x:Key="DefaultCalendarDayButtonStyle" TargetType="{x:Type CalendarDayButton}"> 2 <Setter Property="Template"> 3 <Setter.Value> 4 <ControlTemplate TargetType="{x:Type CalendarDayButton}"> 5 <--文字色を変更--> 6 </ControlTemplate> 7 </Setter.Value> 8 </Setter> 9</Style>
#6/7追記
こちらのページを参考にし以下のようなコードに変更してみました。
lang
1<Style x:Key="DefaultCalendarDayButtonStyle" TargetType="{x:Type CalendarDayButton}"> 2 <Setter Property="Template"> 3 <Setter.Value> 4 <ControlTemplate TargetType="{x:Type CalendarDayButton}"> 5 <ContentPresenter x:Name="NormalText" 6 Margin="5,1,5,1" 7 HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 8 VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 9 TextElement.Foreground="#FF333333"/> 10 </ControlTemplate> 11 </Setter.Value> 12 </Setter> 13</Style>
文字色は変更することができました。
しかし元々用意されていたCalendarの他のプロパティがTemplateの設定によりいない扱いされているみたいです。
(選択中の日付の色が変わったり、現在の日付部分だけ色が変わったりなどが無くなってしまった)
実際に、以下のコードではBackgroundプロパティが適用されなくなってしまいます。
lang
1<Style x:Key="DefaultCalendarDayButtonStyle" TargetType="{x:Type CalendarDayButton}"> 2 <Setter Property="Background" Value="Blue"/> 3 <Setter Property="Template"> 4 <--何もしない--> 5 </Setter> 6</Style>
もしこの直し方で進められるのであれば、
どのようにすればTemplateを定義する前のStyleを
Templateの定義後に引き継げられるできるのでしょうか。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。