Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save Application theme name in WPF

I am using Devexpress and WPF. There are different themes user can apply provided by devexpress.

 ThemeManager.ApplicationThemeName = Theme.MetropolisDarkName; //MetropolisDarkName is name of a Theme.

In my application user can select any theme to apply. But if he closes application and opens it again, Themes changes doesn't same. I want that these changes should be saved so if user after applying theme will open it again, changes should be saved and apply.

Should i have to save name of Theme in database or is there any other way to solve this. I need your suggestions. Thank you.

like image 461
Zoya Sheikh Avatar asked Mar 28 '26 01:03

Zoya Sheikh


1 Answers

The super easy way to do this in Visual Studio is to add a new .settings file to your project, and define a setting of ThemeName. You can find the settings template under General in the C# project Templates. The settings file itself is just a designer with an underlying class of type System.Configuration.ApplicationSettingsBase.

The class created saves setting values to the app.config. The neat thing is you can define settings as application or user, so different users using the application on the same machine can have their own custom settings.

The following assumes that you created the file Settings.settings with an entry called ThemeName of type string.

Get the theme from Settings

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    ThemeManager.ApplicationThemeName = Properties.Settings.Default.ThemeName;
}

Save the Theme

public void SetTheme(string themeName) {
    ThemeManager.ApplicationThemeName = themeName;
    Properties.Settings.Default.ThemeName = themeName;
    Properties.Settings.Default.Save();
}

Settings on MSDN

like image 97
Daniel Gimenez Avatar answered Mar 29 '26 14:03

Daniel Gimenez