We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Application wide persisting user Theme which can be changed at run-time via strict MVVM architecture

Hi,

I did have a long post typed out with what I'd tried etc, but your posting system gave me no end of trouble and for some reason wouldn't let me post because I'd used the word "gold"!! So I've run out of patience a bit. 

What I'm wanting to achieve is the have the ability for a user to be able to pick a theme from a drop down, this to be applied to any currently open and subsequent application windows and for this choice to be persisted onto the next run of the application (preferably via user settings - i.e. My.Settings)

I've looked at your documentation here which isn't very helpful. How could I achieve this using only MVVM and not using any code behind the View window?

I've attached my working test project 


Attachment: GameBoxer_7587f658.7z

4 Replies 1 reply marked as answer

KS Kayalvizhi Sivashanmugam Syncfusion Team October 18, 2022 08:03 AM

Hi Steve,


We have modified your demo to apply theme from ViewModel. In this we have used ComboBox to get selected theme and applied to SfSkinManager attached property.


Demo Link: https://www.syncfusion.com/downloads/support/forum/178217/ze/GameBoxer_Modified1711751655


If you have multiple windows in your application, apply the selected theme to all windows. If your requirement is still not meet in this sample, please provide more information about your requirement.


Regards,

Kayalvizhi S



ST Steve October 18, 2022 01:13 PM

Thanks. Yes - I had got this far myself. However, I'm don't see how you can use this approach to apply the chosen theme to all other opened forms using a pure MVVM approach. For example, if you chose "MaterialDark", you could save this to My.Settings. However, you can't use:


SfSkinManager.SetTheme(Application.Current.MainWindow, new Theme(SelectedTheme));


In other view models for other forms as there's no equivalent of Application.Current.MainWindow for other forms. You could use:

SfSkinManager.SetTheme(this, new Theme("MaterialDark"));

In the code behind the form, but this would be breaking the pure MVVM requirement, which I'm trying to avoid (i.e. I'm trying not to use any code behind the view at all. 

Any more ideas??



ST Steve October 18, 2022 03:16 PM

Never mind. I finally figured it. You just store them name of the theme in My.Settings.UiTheme and include the following in the Window XAML:


        xmlns:syncfusionskin ="clr-namespace:Syncfusion.SfSkinManager;assembly=Syncfusion.SfSkinManager.WPF"
        xmlns:properties="clr-namespace:GameBoxer.WPF.Properties"
        syncfusionskin:SfSkinManager.VisualStyle="{Binding Source={x:Static properties:Settings.Default}, Path=UiTheme}"


This conversion 



Marked as answer

KS Kayalvizhi Sivashanmugam Syncfusion Team October 19, 2022 04:26 AM

Hi Steve,


We are glad to know that your issue has been fixed. Please let us know if you need any other assistance. We will be happy to assist you.  


Regards,

Kayalvizhi S


Loader.
Live Chat Icon For mobile
Up arrow icon