How can I โ€œresetโ€ a control property to its original style value (for example, Background)

I have a simple text block in my project.

I made this style (for illustration):

<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}"> <Style.Setters> <Setter Property="Background" Value="LightGray"/> </Style.Setters> </Style> 

then at some point I do: MyTextBox.Background = Brushes.Red in my code.

still everything is working fine.

Now I would like to be able to return to the original background color, but without its hard coding.

ie: I know what MyTextBox.Background = Brushes.LightGray can do, but I'm looking for a general way that would allow me to return to the original background property of the background without knowing it.

I tried setting it to zero, but of course it gives me a transparent background, which I don't want.

Is it even possible? and if so, how can I achieve this?

thanks

+6
styles wpf xaml
source share
1 answer
 MyTextBox.ClearValue(TextBox.BackgroundProperty); 
+13
source share

All Articles