Please do not get carried away in my example, just carry me for the sake of the question:
In my WPF application, if I wanted all the text fields to have a green background, I would easily set it as such in my applications. Resources.
<Style TargetType="TextBox"> <Setter Property="Background" Value="Green" /> </Style>
This works PERFECTLY ... (thanks to WPF). However, if I had a TextBox somewhere in my application, that I wanted to add a little more styles to ... I LOSE my green background.
Example:
<TextBox> <TextBox.Style> <Style> <Style.Triggers> <Trigger Property="TextBox.IsMouseOver" Value="True"> <Setter Property="TextBox.Foreground" Value="Red" /> </Trigger> </Style.Triggers> </Style> </TextBox.Style> </TextBox>
In case the mouse is over, the TextBox will correctly have a red foreground, but the green background is completely lost.
So, the question is: How do I tell WPF NOT to completely erase all the styles that came from above, just because I have a simple, non-conflicting one, about such a small style added to the control somewhere?
styling wpf
Timothy Khouri
source share