WPF how to restore Button background color
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 c开发者_运维问答olor 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?
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>
精彩评论