Click here to Skip to main content
15,884,425 members
Articles / Programming Languages / C# 4.0
Tip/Trick

Storage and Retrieval of Program Settings

Rate me:
Please Sign up or sign in to vote.
4.64/5 (4 votes)
5 Sep 2015CPOL2 min read 9.9K   6   1
A flexible framework to retrieve and store application settings upon start and shutdown.

Introduction

I have been living with different settings managers of .NET and other frameworks for a while and have realized that they all have their merits but somehow all have something important missing for me. The .NET settings model seems to be OK in the sense that it is easy to use but often produces problems with advanced data. Other setting frameworks also seem to do the trick but they all miss advanced features, such as:

  • Clear and simple integration into frameworks like PRISM or Caliburn and
  • Run-time configuration in dependence of the actual modules loaded.

So I have decided to roll my own SettingsModel and integrated it into a WPF demo application to show off its capabilities:

A sample demo ui with settings options

https://settingsmodel.codeplex.com/

If there is anything interesting, then the demo project might represent an interesting project template for a Modern UI style application (https://github.com/firstfloorsoftware/mui) since it does not only contain these styles, but is also able to store and retrieve changed settings.

Image 2

So, this full functioning Modern UI template contains the complete required code spanning from model, viewmodel, to view (while the normal MUI template contains only view and viewmodel parts).

The template contains fully functioning core features every application should contain these days:

  • Reload files on application re-start
  • Setting for font size
  • Settings for light or black application skin and accent color
  • Folder bookmarks
  • Settings for icon size
  • An about page with information on the loaded modules

Background

This project makes use of the DataSet and DataTable classes to read and write arbitrary .NET values and types in XML. This means that you are no longer concentrating on the actual file format of the XML but rather on the content and involved workflows of the data that you are ending up to store and retrieve.

The model can be accessed via an API that is similar to a query API of a database interface since every stored value can be identified by its path. This means that parts of the settings can (have to) be registered at run-time to reflect the current configuration settings of the application. This framework, makes it therefore, simple to produce a viewer and a Power-User-Advanced application of a product in which parts of different product flavours share similar settings.

Using the Code

The code usage is demonstrated at the referenced Codeplex site at:

The documentation at the site contains more detailed descriptions, a software design model, more screenshots, and demo applications. Please let me know what you think about it and whether you find something is missing...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Germany Germany
The Windows Presentation Foundation (WPF) and C# are among my favorites and so I developed Edi

and a few other projects on GitHub. I am normally an algorithms and structure type but WPF has such interesting UI sides that I cannot help myself but get into it.

https://de.linkedin.com/in/dirkbahle

Comments and Discussions

 
QuestionVery nice! Pin
Paul Conrad5-Sep-15 14:09
professionalPaul Conrad5-Sep-15 14:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.