Windows Forms - Visual Studio 2019 (16.5 Preview 1 - .NET CORE 3.1)
Starting from Visual Studio 16.5 Preview 1, there is builtin support for Windows Forms designer in Visual Studio. To use the designer:
- You must be using Visual Studio 16.5 Preview 1 or a later version.
- You need to enable the designer in Visual Studio. Go to Tools → Options → Environment → Preview Features and select the Use the preview Windows Forms designer for .NET Core apps option.
For more information:
Keep in mind, in this release, many controls aren’t yet supported in designer.
Workaround for Older versions
Starting from Visual Studio 16.5 Preview 1, there is builtin support for Windows Forms designer in Visual Studio. But for older versions you can use the following workaround:
At the moment, there is a workaround for using Classic .NET Windows Forms Designer for .NET CORE Windows Forms projects.
The workaround relies on having Classic WinForms App and CORE WinForms app in the same solution, having the same root namespace.
For adding new designable items, every time which you want to add new item, you need to add it to classic project, then move the 3 generated files (.cs, .designer.cs, .resx) to the CORE app, then adding them as link to the classic app.
For editing, since they are available as a link in classic app, edit them in the designer of classic app. All changes are visible to CORE app.
Prepare solution to use Windows Forms Designer for .NET Core Winforms App
- Create a Windows Forms .NET Core App. (See the steps and requirements.)
- Open the project in Visual Studio and save the the project including solution.
- Right click on Solution and Add New Project → From templates, select Windows Forms project, and name it the same name as Core app + ".Designer" and click OK.
- In properties of the Classic framework project, set default namespace to same default namespace of Core app.
- Erase all exising files in both projects and save changes.
Adding a Form or UserControl
Every time which you want to add a new form or user control, you need to do the following steps:
- In the classic framework project, Add New Item
- Select Windows Form or User Control
- Do some changes in desginer, like resizing the form, so resx file will be generated and Save.
- In solution explorer, right click on the form and choose Cut.
- In core app, paste all the items.(form, designer, resx).
- In the classic app, right click and choose Add Existing Item.
- Browse open dialog to core app folder and choose those 3 added files and click dropdown near of add button and choose Add As Link
- Compile the solution.
- Renest the files in the classic app using Mad Kristensen's File Nesting Extension or by editing project file.
Now, whenever you need to use the Designer on one of the Core Form or UserControl files, simply open the linked files in the Classic Framework project with the Classic Windows Forms Designer.
WPF - VS 2019 (16.0.3 .NET CORE 3.0)
The GA version of the WPF .NET Core Designer has been released at the same time as .NET Core 3.0 and it comes with Visual Studio.
Reference:
WPF Designer is completely independent of the Windows Forms Designer. We released its GA version of the WPF .NET Core Designer at the same time as .NET Core 3.0 and it comes with Visual Studio. In Visual Studio version 16.3.0 we had an issue with the Enable XAML Designer property set to false by default. That means that when you click on .xaml files, the designer doesn’t open automatically. Upgrade to the latest Visual Studio version 16.3.1 where this issue is fixed. Another option to fix it is to go to Tools -> Options -> XAML Designer and check Enable XAML Designer.