开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜