开发者

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

开发者 https://www.devze.com 2023-01-31 22:59 出处:网络
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}\">

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="Backg开发者_StackOverflowround" 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


MyTextBox.ClearValue(TextBox.BackgroundProperty);
0

精彩评论

暂无评论...
验证码 换一张
取 消