Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Load/Save WPF application settings

Load/Save WPF application settings

Scheduled Pinned Locked Moved WPF
csharpquestiondatabasewpfdesign
6 Posts 3 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Praveen Raghuvanshi
    wrote on last edited by
    #1

    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.

    S A 2 Replies Last reply
    0
    • P Praveen Raghuvanshi

      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.

      S Offline
      S Offline
      SledgeHammer01
      wrote on last edited by
      #2

      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 :).

      P 1 Reply Last reply
      0
      • P Praveen Raghuvanshi

        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.

        A Offline
        A Offline
        Abhinav S
        wrote on last edited by
        #3

        If your storage is fairly temporary, then you might want to consider Isolated Storage as an option. Using this, you can store settings in memory. Remember thought that these settings can be cleared when the user so wants. See this[^] for a fairly simple example.

        P 1 Reply Last reply
        0
        • S SledgeHammer01

          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 :).

          P Offline
          P Offline
          Praveen Raghuvanshi
          wrote on last edited by
          #4

          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.

          S 1 Reply Last reply
          0
          • A Abhinav S

            If your storage is fairly temporary, then you might want to consider Isolated Storage as an option. Using this, you can store settings in memory. Remember thought that these settings can be cleared when the user so wants. See this[^] for a fairly simple example.

            P Offline
            P Offline
            Praveen Raghuvanshi
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • P Praveen Raghuvanshi

              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.

              S Offline
              S Offline
              SledgeHammer01
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups