Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF how to restore Button background color

Tags:

button

wpf

This question felt so simple but I just can't find the answer:

How to change a Button back to its default? My VS2010 start giving me button with strange color and I have to manually set the Button to look like its default self.

I tried:

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

Anyone?

enter image description here

like image 442
KMC Avatar asked Feb 23 '11 10:02

KMC


1 Answers

Use the ClearValue-method to restore the default.

btn.ClearValue(Button.BackgroundProperty);

or

btn.ClearValue(Control.BackgroundProperty);

This sets back the background-property of the button. But if you have changed the buttons template, this will not help. In this case, look for explicit declarations of the Button.Template-property or for a style that sets the Button.Template-property. Look especially in your App.xaml if there is something like

<style TargetType="Button">
  ...
</style>

or

<style TargetType="{x:Type Button}">
  ...
</style>
like image 144
HCL Avatar answered Oct 01 '22 14:10

HCL