What I want to do is to change the Background
from the TextBox
that is inside the DatePicker
.
I tried to get it work by adding the <Style TargetType="{x:Type DatePickerTextBox}"
but had no success because I already have other <Style>
there.
Here is my <DatePicker>
:
<DatePicker Grid.Column="1" Grid.Row="0"
VerticalContentAlignment="Center" MinHeight="20">
<DatePicker.SelectedDate>
<Binding Path="ViewModel.Value" UpdateSourceTrigger="PropertyChanged"
RelativeSource="{RelativeSource TemplatedParent}"/>
</DatePicker.SelectedDate>
<DatePicker.Style>
<Style TargetType="{x:Type DatePicker}">
<Setter Property="Background" Value="White"/>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=ViewModel.IsDirty}" Value="true">
<Setter Property="Background" Value="LightYellow"/>
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=ViewModel.IsInvalid}" Value="true">
<Setter Property="BorderBrush" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DatePicker.Style>
</DatePicker>
So when the IsDirty
is triggered the Background
gets LightYellow
but the inner TextBox
Background
is still White
.
How do I change this Background
as well?
In your Style
, just add the desired DatePickerTextBox
style as a resource:
<Style TargetType="{x:Type DatePicker}">
<Style.Resources>
<Style TargetType="DatePickerTextBox">
<Setter Property="Background" Value="Transparent"/>
</Style>
</Style.Resources>
<Setter Property="Background" Value="White"/>
<Style.Triggers>
<!-- your triggers here -->
</Style.Triggers>
</Style>
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