WPF how to restore Button background color

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

How to change a button to its default value? My VS2010 starts to give me a button with a weird color, and I need to manually set the Button to make it look like the default one.

I tried:

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

Is anyone

enter image description here

+8
button wpf
source share
1 answer

Use ClearValue -method to restore to default.

 btn.ClearValue(Button.BackgroundProperty); 

or

 btn.ClearValue(Control.BackgroundProperty); 

This returns the background property of the button. But if you change the button template, this will not help. In this case, find explicit Button.Template -property declarations for either the style that sets the Button.Template property. Pay particular attention to your App.xaml if there is something like

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

or

 <style TargetType="{x:Type Button}"> ... </style> 
+18
source share

All Articles