David Alan McQuinn
David Alan McQuinn

Reputation: 53

Visual Studio 2022 winform designer does not show ApplicationSettings in the property window of any control

In VS 2022 I create a new winform (.net 6.0) project. I put one textbox on the form. In the properties window, at the top, I'm used to seeing an item "ApplicationSettings" where I can bind the TEXT property of the textbox to an application setting. But I no longer see the line for "ApplicationSettings". If I open an older winform project it works as expected.

Upvotes: 4

Views: 7109

Answers (1)

Reza Aghaei
Reza Aghaei

Reputation: 125197

The feature is (still) not available for WinForms .NET 6 but if you create a WinForms .NET framework project, it's available.

Data binding to application settings in code

You can setup the data binding in code:

  1. Create or open the Application settings. (Project properties -> Settings -> Create or open application settings.)

  2. Add a user-scoped property like Property1 (if you want it to be modifiable by user in a data-binding scenario.)

  3. Setup a databinding in code, like this:

    this.textBox1.DataBindings.Add(new Binding("Text", 
        Properties.Settings.Default, "Property1", true,
        DataSourceUpdateMode.OnPropertyChanged));
    

Designer workaround

If you really want a designer-based solution, then:

  1. Create or open the Application settings. (Project properties -> Settings -> Create or open application settings.)

  2. Change the application settings class modifier to public (on the top bar) to make it visible to the Add new data source window.

  3. After building the project, in the databinding section of the property grid, for your control, add a new project data source and setup databinding to Settings. (Preferably advanced setting and choosing OnPropertyChanged.)

  4. Then you need to set the data source when you load form:

    settingsBindingSource.DataSource = Properties.Settings.Default;
    

Upvotes: 5

Related Questions