Changing the Foreground property of the WPF DatePicker does change the colour of the text in the text box, but changing the Background property doesn't. But you can change it by styling the contained DatePickerTextBox. So I ended up with this:
<DatePicker Foreground="Yellow" >
<DatePicker.Resources>
<Style TargetType="{x:Type DatePickerTextBox}" >
<Setter Property="Background" Value="Black" />
</Style>
</DatePicker.Resources>
</DatePicker>
Is there a tidier way of doing this without templating the whole control? Is there a way to just template the named part i.e. PART_TextBox?
You can change DatePickerTextBox style
Code
<DatePicker>
<DatePicker.Resources>
<Style TargetType="{x:Type DatePickerTextBox}">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<TextBox x:Name="PART_TextBox"
Text="{Binding Path=SelectedDate, RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DatePicker.Resources>
</DatePicker>
Please refer this link Custom WPF DatePickerTextBox Template Help
Is there a tidier way of doing this without templating the whole control? Is there a way to just template the named part i.e. PART_TextBox?
No. You can't set any properties of an element that is defined inside a control's template (and that is not bound to any properties of the "parent" control itself) without re-defining the entire template or use implicit styles.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With