Mauro Ganswer
Mauro Ganswer

Reputation: 1419

How do you organize your Application Settings into groups?

I have several tens of settings (user scope) in my app and they start to become too much, hence I would like to organize them into groups. On MSDN at this link they say:

"...If you have organized your settings into groups, or have added multiple settings classes in your project, you will see your settings arranged as a hierarchical tree.."

however if I access the project's properties and then the Settings tab I can only set the Name, the Type, the Scope and the Value. So where do you organize the settings by groups? As an alternative how do you create multiple settings classes? Is it possible to still manage multiple settings classes at design time?

EDIT

following the suggestions of JesseJames I've created this test class:

using System;
using System.Configuration;

namespace MyApp
{
    public class PageAppearanceSection : ConfigurationSection
    {
        // Create a "remoteOnly" attribute.
        [ConfigurationProperty("testString", DefaultValue = "false", IsRequired = false)]
        public string TestString
        {
            get{ (Boolean)this["testString"]; }
            set{ this["testString"] = value;  }
        }
    }
}

and I've modified my app.config in this way:

<configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
        <section name="MyApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
    <!--NEW ADDED SECTION-->
    <sectionGroup name="pageAppearanceGroup">
      <section 
        name="pageAppearance" 
        type="MyApp.PageAppearanceSection" 
        allowLocation="true" 
        allowDefinition="Everywhere"
      />
    </sectionGroup>
</configSections>

However when then I want to bind the TestString value to the Text of a TextBox and I go in TextBox's properties > AppliactionSettings > PropertyBinding I do not see that property.

Upvotes: 1

Views: 2715

Answers (1)

opewix
opewix

Reputation: 5083

You can create custom config sections, then work with properties defined in section class.

How to: Create Custom Configuration Sections Using ConfigurationSection

Upvotes: 1

Related Questions