Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I "reset" a control's property to its original style value (like Background)

Tags:

styles

wpf

xaml

I have a simple textBox in my project.

I made this style (for illustration purposes):

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

then at one point, I'm doing: MyTextBox.Background = Brushes.Red in my code-behind.

up to there, everything works fine.

now I would like to be able to revert to the original background color, but without hardcoding it.

i.e.: I know I can do MyTextBox.Background = Brushes.LightGray, but I'm looking for a generic way that would enable me to revert to the original style's background property, without knowing it.

I tried setting it to null, but of course it gives me a transparent background, which is not what I want.

is this possible at all? and if yes, how can I achieve this ?

thanks

like image 954
David Avatar asked Dec 22 '10 08:12

David


1 Answers

MyTextBox.ClearValue(TextBox.BackgroundProperty);
like image 145
Kent Boogaart Avatar answered Oct 13 '22 05:10

Kent Boogaart