Reputation: 3489
Anyone found a good pattern for getting around immutable styles in Silverlight 2?
What I mean is does anyone have a workaround for the fact that you cannot switch the style of an element programmatically once it has been set, i.e. the second line here will throw a catastrophic failure exception:
this.TestButton.Style = (Style)Application.Current.Resources["Fred"];
this.TestButton.Style = (Style)Application.Current.Resources["Barney"];
Upvotes: 2
Views: 493
Reputation: 3489
The problem goes away in Silverlight 3 where styles are mutable - yay!
Upvotes: 2
Reputation: 1810
It's not possible. The best workaround I've seen is from Nikhil Kothari at Microsoft:
http://www.nikhilk.net/Silverlight-Themes.aspx
There is a major drawback to defining styles centrally in App.xaml anyway, which is that it breaks all designer support when you reference those styles from other user controls. I haven't used it but Nikhil's theme engine looks very promising, and I have a funny feeling that many of his ideas will make it into the silverlight product eventually anyway.
Upvotes: 2
Reputation: 9985
I don't know if this helps, but I believe you can change the control's template as many times as you want during runtime. Maybe that would be a potential workaround.
Upvotes: 0