WPF如何恢复Button背景色

KMC*_*KMC 9 wpf button

这个问题感觉很简单,但我找不到答案:

如何将Button更改回默认值?我的VS2010开始给我一个奇怪的颜色按钮,我必须手动设置按钮看起来像它的默认自我.

我试过了:

btn.Background = null; // only make it transparent, not default background

任何人?

在此输入图像描述

HCL*_*HCL 21

使用ClearValue -method恢复默认值.

btn.ClearValue(Button.BackgroundProperty);
Run Code Online (Sandbox Code Playgroud)

要么

btn.ClearValue(Control.BackgroundProperty);
Run Code Online (Sandbox Code Playgroud)

这将设置按钮的background属性.但是,如果您更改了按钮模板,这将无济于事.在这种情况下,查找Button.Template -property的显式声明或设置Button.Template-property的样式.如果有类似的话,请特别注意您的App.xaml

<style TargetType="Button">
  ...
</style>
Run Code Online (Sandbox Code Playgroud)

要么

<style TargetType="{x:Type Button}">
  ...
</style>
Run Code Online (Sandbox Code Playgroud)