This is a migrated thread and some comments may be shown as answers.

Cycle thru XAML/StyleManager themes programmatically?

4 Answers 13 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rob A.
Top achievements
Rank 2
Iron
Iron
Veteran
Rob A. asked on 26 Nov 2020, 02:51 AM

I was wondering if it's possible to cycle thru "available" themes programmatically when using XAML/StyleManager approach?  I'd like to cycle thru whatever themes are supported in the XAML approach and display their names in a ComboBox for a user to select.

Cheers, Rob.

 

4 Answers, 1 is accepted

Sort by
0
Rob A.
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 27 Nov 2020, 01:35 AM

In addition, it seems when changing the StyleManager.Application theme in "real-time" the UI doesn't update with the new theme?

After reading this document: https://docs.telerik.com/devtools/wpf/styling-and-appearance/how-to/styling-apperance-themes-runtime

... it seems that this can't be achieved when using the XAML/StyleManager approach (only for NoXAML)?  So the only way to get the Theme to update is to re-start my application?

I'm hoping I missed something in the documentation as this seems like a rather significant draw back to XAML approach for Themes and probably should have been mentioned here: https://docs.telerik.com/devtools/wpf/styling-and-appearance/xaml-vs-noxaml

Thoughts?

Cheers, Rob.

0
Martin Ivanov
Telerik team
answered on 27 Nov 2020, 09:41 AM

Hello Rob,

Indeed, the StyleManager theming mechanism doesn't support run-time application theme changes. This will work only NoXaml dlls and Implicit Styles. With StyleManager, you can change the theme only per control by setting the StyleManager.Theme attached property. However, this is not very convenient if you have multiple controls. Here is an example in code:

StyleManager.SetTheme(this.radControl, new FluentTheme());

I also included a note in the Xaml vs. NoXaml article about this and updated your Telerik points.

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Rob A.
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 30 Nov 2020, 01:25 AM

Disappointing, but Ok.  It does seem to work when opening a new RadWindow but not on the main windows which I'm assuming would need an InitializeComponent() call when they've already been initialized.

Thank you for adding this "gotcha" to the documentation ... it's certainly a "decision" trigger for anyone else considering which path to go down for Themes.  

As a work around I've implemented an application shutdown and restart ... not pretty but gets the job done.

Cheers, Rob.

0
Martin Ivanov
Telerik team
answered on 30 Nov 2020, 12:05 PM

Hello Robin,

The StyleManager.ApplicationTheme attached property instructs the controls which theme style should be assigned to their Style property. Changing the application theme at runtime means that the StyleManager should know about all Telerik controls and go resetting their Style based on the new theme, which doesn't happen. When you initialize new controls after the application theme is changed, they use the styles from the new theme. This is why when you open a new RadWindow after the theme change, you see the new theme applied.

Regards,
Martin Ivanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
General Discussions
Asked by
Rob A.
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Rob A.
Top achievements
Rank 2
Iron
Iron
Veteran
Martin Ivanov
Telerik team
Share this question
or