Reputation: 259
I tried to modify a background property alone in a Style from code behind for some internal purpose in my WPF application, below error thrown when try to add a new setter to the style that we used
After a 'SetterBase' is in use (sealed), it cannot be modified.
How can i resolve this?
Thanks in advance
Upvotes: 2
Views: 3298
Reputation: 319
if you have something along the lines of:
<Setter Property="Button.Background" Value="Red" />
this can be replaced using the code behind. In C#, that would look like this:
var setter = new Setter
{
Property = Button.BackgroundProperty,
Value = "red",
};
Or, using bindings:
Value = new Binding("BackgoundColour"),
where BackgroundColour is a variable.
I am not sure if this works when the base is sealed, but try it.
Upvotes: 1