Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Remove Attribute of Control from Code Behind in WPF

Tags:

c#

wpf

I want to Remove Attribute background from code Behind. This is my Xaml Code -

<Button Name="btnBack" Width="50" Height="50"></Button>

And Xml.cs

btnBack.Background = Brushes.Red;

But after some operation i want to remove this attribute with value so my button should come as its original color and "Red" should Remove.

Can Any one help me?

like image 996
Reety Avatar asked Dec 12 '25 06:12

Reety


1 Answers

Reset the property to its default value by calling DependencyObject.ClearValue:

btnBack.ClearValue(Control.BackgroundProperty);

This clears a so-called local value (e.g. any value set directly or by a Binding), but keeps any potential value set by a Style.

like image 104
Clemens Avatar answered Dec 14 '25 19:12

Clemens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!