【发布时间】:2011-07-02 16:13:29
【问题描述】:
这个问题感觉很简单,但我就是找不到答案:
如何将 Button 改回其默认值?我的 VS2010 开始给我一个奇怪颜色的按钮,我必须手动设置按钮看起来像它的默认自我。
我试过了:
btn.Background = null; // only make it transparent, not default background
有人吗?
【问题讨论】:
这个问题感觉很简单,但我就是找不到答案:
如何将 Button 改回其默认值?我的 VS2010 开始给我一个奇怪颜色的按钮,我必须手动设置按钮看起来像它的默认自我。
我试过了:
btn.Background = null; // only make it transparent, not default background
有人吗?
【问题讨论】:
使用ClearValue-方法恢复默认。
btn.ClearValue(Button.BackgroundProperty);
或
btn.ClearValue(Control.BackgroundProperty);
这会设置按钮的背景属性。但是,如果您更改了按钮模板,这将无济于事。在这种情况下,请查找 Button.Template-property 的显式声明或设置 Button.Template-property 的样式。如果有类似
的内容,请特别查看您的 App.xaml<style TargetType="Button">
...
</style>
或
<style TargetType="{x:Type Button}">
...
</style>
【讨论】: