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’];
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.