Load/Save WPF application settings
-
I have a application written in WPF, C#. There are some settings of different modules of the application which I wanted to store, so that when application is launched, I can restore those settings. I am thinking of using XML file and writing the settings through XML reader. I am using 'Application.CommonAppDataPath' to store the settings. Is there a better way to implement this feature in WPF application and that can support Windows 7? Also, as modules gets added to the application, settings get added to the file. What is the best design to handle addition of settings in future? Please let me know the correct forum, If I have posted the query in wrong forum.
-
I have a application written in WPF, C#. There are some settings of different modules of the application which I wanted to store, so that when application is launched, I can restore those settings. I am thinking of using XML file and writing the settings through XML reader. I am using 'Application.CommonAppDataPath' to store the settings. Is there a better way to implement this feature in WPF application and that can support Windows 7? Also, as modules gets added to the application, settings get added to the file. What is the best design to handle addition of settings in future? Please let me know the correct forum, If I have posted the query in wrong forum.
No need to hand job anything. Its already built into .NET for you for free. In solution explorer, expand the Properties folder and double click on "Settings.settings". Set up your application settings in that designer. In your code, you'll access them like: Properties.Settings.Default. = blah; to save, you'd do: Properties.Settings.Default.Save(); they'll be auto-loaded when your app is loaded. There are some annoying details to get everything working in the real world, but this will get you started :).
-
I have a application written in WPF, C#. There are some settings of different modules of the application which I wanted to store, so that when application is launched, I can restore those settings. I am thinking of using XML file and writing the settings through XML reader. I am using 'Application.CommonAppDataPath' to store the settings. Is there a better way to implement this feature in WPF application and that can support Windows 7? Also, as modules gets added to the application, settings get added to the file. What is the best design to handle addition of settings in future? Please let me know the correct forum, If I have posted the query in wrong forum.
-
No need to hand job anything. Its already built into .NET for you for free. In solution explorer, expand the Properties folder and double click on "Settings.settings". Set up your application settings in that designer. In your code, you'll access them like: Properties.Settings.Default. = blah; to save, you'd do: Properties.Settings.Default.Save(); they'll be auto-loaded when your app is loaded. There are some annoying details to get everything working in the real world, but this will get you started :).
Thanks for the response. However, I am looking for clean way of loading/saving the application preferences in a loosely coupled manner. I am using MVVM architecture for my application and there are some global settings and some local settings pertaining to a module.
-
Thanks Abhinav, however i am looking for some clean way of handling user preferences. Please refer my previous post for more information. Praveen Raghuvanshi Software Developer
-
Thanks for the response. However, I am looking for clean way of loading/saving the application preferences in a loosely coupled manner. I am using MVVM architecture for my application and there are some global settings and some local settings pertaining to a module.
LMAO. How is one line of code not clean? This is perfectly appropriate for MVVM. Your VM would simply initialize its properties from the Properties.Settings.Default.. If you are too lazy for that :), I guess you could write some reflection based code in your ViewModelBase to auto initialize the properties from the user settings. Seems like over engineering IMO though.