WPF C# Properties.Settings doesn't exist [duplicate] - c#

This question already has answers here:
Equivalent to UserSettings / ApplicationSettings in WPF .NET 5, .NET 6 or .Net Core
(8 answers)
Closed 2 years ago.
I'm trying to create simple application/user settings for my WPF application.
Most answers and tutorials suggest using Properties.Settings.Default for this.
However, Settings doesn't exist in my Properties namespace.
There is also no .settings file in my project explorer, as the microsoft documentation suggests:
Open Visual Studio.
In Solution Explorer, expand the Properties node of your project.
Double-click the .settings file in which you want to add a new setting. The default name for this file is Settings.settings.
Also there is no Settings tab in my project properties window, as some (older?) resources suggest.

Check out this answer: https://stackoverflow.com/a/58423458/10703868
Looks like you are using .NET Core instead of .NET Framework with WPF. Right click on your MyApp Project and add a new folder titled "Properties". Then right click on that and add a new item. Search for settings, add the settings file. They you should be able to use this.
I don't see the settings tab in my project properties view, but if you right click on the settings file you can change the Open with to be the settings designer for the old view.

WPF App (.NET Core) template doesn't seem to be adding .settings file by default, as opposed to WPF App (.NET Framework).
You can add it by right clicking your project file -> Add -> New Item... -> Settings File (you can search for it, or browse for it under Visual C# -> General).

Related

Where is the "project file"?

I have created a .NET7 C# project, and I'm trying to understand this article: https://learn.microsoft.com/hu-hu/dotnet/desktop/winforms/whats-new/net60?view=netdesktop-6.0#new-application-bootstrap about the new bootstrap that moves the configurations to the "project file":
To complement the new application bootstrap feature of Windows Forms, a few Application
settings previously set in the startup code of the application should be set in the project
file. The project file can configure the following application settings:
The only thing it doesn't mention is where can we find the project file? Is it editable from Visual Studio directly? Or we have to create it for ourselves?
In visual studio explorer, double click on the file with "csproj" extension (it has a rectangular icon with C# written in green. This will open the file in xml format. In most cases, you don't need to manipulate it manually.

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.
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:
Create or open the Application settings. (Project properties -> Settings -> Create or open application settings.)
Add a user-scoped property like Property1 (if you want it to be modifiable by user in a data-binding scenario.)
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:
Create or open the Application settings. (Project properties -> Settings -> Create or open application settings.)
Change the application settings class modifier to public (on the top bar) to make it visible to the Add new data source window.
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.)
Then you need to set the data source when you load form:
settingsBindingSource.DataSource = Properties.Settings.Default;
This worked for me, for the Visual Studio Community Version:
Closed the entire Project/Solution in Visual Studio.
Reloading the .sln file in Visual Studio IDE along with the Dependencies.
Double Clicking the (on the highlighted part) opened the Form in the Design format.
Hope this helps!

Visual studio debug is showing ‘Start’ instead of browser [duplicate]

This question already has answers here:
A project with an Output Type of Class Library cannot be started directly.
(2 answers)
Closed 4 years ago.
I cloned an Asp.Net MVC project from Github and I renamed it following the steps on this article https://www.codeproject.com/Articles/697108/Visual-Studio-Painlessly-Renaming-Your-Project-and
After that I rebuilt the solution and somehow visual studio doesn’t recognize my app as a web app anymore. The debug button used to show my default browser “google chrome” and when I hit F5 it used to open up in google chrome. Now the debug button shows “Start” and when I hit F5 to run, a dialog box pops up “A project with an Output Type of Class Library cannot be started directly. In order to debug this project, add an executable project to this solution which references the library project. Set the executable project as the startup project”
Any help is appreciated.
I think you must choose property "Set as StartUp Project" on your project.
Right click on your project -> Choose Set as StartUp Project

get a new Properties Settings file in SharpDevelop

If I search here and on other forums how to add a Settings file in SharpDevelop IDE (I use v4.3, installed it when it was new, no need so far for updates), I only find posts of 5+ years ago which state that there's no settings editor in SharpDevelop.
I have an existing solution folder from another project which has a settings file (it's used there for setting default values of some text boxes), and I can edit it in SharpDevelop without problems - so it's built-in now, obviously.
But, how to add a settings file if there's none so far? I can't see an option where to add it, can't find anything in the www for this. Can't be that difficult ...
SharpDevelop 4 includes a settings file template.
Right click the project in the Projects window and select Add - New Item to open the New File dialog.
Open the category Misc.
There should be a Settings template available.

how insert form from project other in visual c#

I have a Project in which there is a form that has several objects (controls) in itself. I want to add this form to another Project in another Solution. How to I can do this. Thanks.
This is a good thing to reuse your code :)
You have to make a library project.
1)File => New Project
2)Check Visual project in the tree
then select "Class Library", give it a name "MyFormLib"
3)Then simply copy paste YourForm.cs and YourForm.designer from your app project, to "MyFormLib".
4)Now go to solution explorer, browse to your application project, right click on "references" then "add reference"
5)To finish click on "solution" then choose your library project "MyFormLib"
.
6)You can now use the form from the library project inside your application project.
e.g : new MyFormLib.TheForm()
7) To reuse your form in your second application, redo steps 4 to 6
Just simply open the project where you want to add the existing form:
Right click on the Solution Explorer
Select "Add" -> "Existing Item..."
Browse your other project's folder, and search for the 3 files of your form:
yourForm1.cs, yourForm1.Designer.cs, yourForm1.resx
The simplest way is to
Open the destination solution in Visual Studio.
On the Solution Explorer, right-click the destination Solution name and Click on Add > Existing Projects. Identify the project with your source Form.
Move the form from source to destination project (The designer and resx files will move with it)
Change relevant namespace specifications and then you may remove the old form.

Categories