我怎样才能“重置”控件的属性为其原始样式值(如背景)
我的项目中有一个简单的文本框。
我制作了这种样式(用于说明目的):
<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}">
<Style.Setters>
<Setter Property="Background" Value="LightGray"/>
</Style.Setters>
</Style>
然后在某一时刻,我在我的代码隐藏中执行: MyTextBox.Background = Brushes.Red
。
到那里,一切正常。
现在我希望能够恢复到原始背景颜色,但无需对其进行硬编码。
即:我知道我可以执行 MyTextBox.Background = Brushes.LightGray
,但我正在寻找一种通用方法,使我能够在不知情的情况下恢复到原始样式的背景属性。
我尝试将其设置为 null,但当然它给了我一个透明的背景,这不是我想要的。
这有可能吗?如果是,我怎样才能实现这一目标?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)