Dear Telerik,
As of yet, I believe swapping Themes at runtime is only possible if all controls have a StyleManager.Theme property set. Setting an application-wide Theme is only possible when the application starts, before the InitializeComponents() method call.
I am currently fiddling around with Themes, trying to find the best way to setup a custom theme project. I believe I have found a way to set a Theme at runtime. Basically, the idea is to add a ResourceDictionary to the App.Resources in the App.xaml file. When the theme needs to be swapped, the Source property of the ResourceDictionary will be pointed to a different Generic.xaml file (which should reference all applicable .xaml files defining a theme). Silverlight automatically picks up on this change and applies the new theme.
There is, however, still one problem. I have created a small demo project to illustrate the problem and the setup I am working on (see below). The project contains an App class that swaps between Theme1 (blue text) and Theme2 (red text) every two seconds. Somehow, when the first swap is introduced, the style is not applied. You may notice the text on the Button changing from blue (Theme1) to black (no theme), while it should become red (Theme2). After this buggy behavior, every two seconds the theme is changed and properly applied. However, from this point on, the applied theme does not match the colors of the text (when Theme2 is applied, the text color is blue).
Since I do not know that much about ResourceDictionaries, styles and themes, I though I could ask you. Would you be able to find a fix for this behavior (even though it is not technically a Telerik issue)? If this is working, perhaps it can be applied to the Telerik theming system to provide developers with runtime application-wide theme swapping with only 1 line of code:
Coincidentally, any control that has a matching <Style> element in the theme project will be themed, not just RadControls.
E-mail me for the demo project (rbe@optimizers.nl), as I cannot upload it to the forum. Also, I cannot create a "Feature Request" in the issue tracker and I do not believe this post should be in there in the first place.
As of yet, I believe swapping Themes at runtime is only possible if all controls have a StyleManager.Theme property set. Setting an application-wide Theme is only possible when the application starts, before the InitializeComponents() method call.
I am currently fiddling around with Themes, trying to find the best way to setup a custom theme project. I believe I have found a way to set a Theme at runtime. Basically, the idea is to add a ResourceDictionary to the App.Resources in the App.xaml file. When the theme needs to be swapped, the Source property of the ResourceDictionary will be pointed to a different Generic.xaml file (which should reference all applicable .xaml files defining a theme). Silverlight automatically picks up on this change and applies the new theme.
There is, however, still one problem. I have created a small demo project to illustrate the problem and the setup I am working on (see below). The project contains an App class that swaps between Theme1 (blue text) and Theme2 (red text) every two seconds. Somehow, when the first swap is introduced, the style is not applied. You may notice the text on the Button changing from blue (Theme1) to black (no theme), while it should become red (Theme2). After this buggy behavior, every two seconds the theme is changed and properly applied. However, from this point on, the applied theme does not match the colors of the text (when Theme2 is applied, the text color is blue).
Since I do not know that much about ResourceDictionaries, styles and themes, I though I could ask you. Would you be able to find a fix for this behavior (even though it is not technically a Telerik issue)? If this is working, perhaps it can be applied to the Telerik theming system to provide developers with runtime application-wide theme swapping with only 1 line of code:
ApplicationResourceDictionary.Instance.Theme =
new
Theme2();
Coincidentally, any control that has a matching <Style> element in the theme project will be themed, not just RadControls.
E-mail me for the demo project (rbe@optimizers.nl), as I cannot upload it to the forum. Also, I cannot create a "Feature Request" in the issue tracker and I do not believe this post should be in there in the first place.