Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
342 views
in Technique[技术] by (71.8m points)

c# - Windows Forms Designer and WPF Designer for .NET Core

I have recently heard that the alpha version of .NET Core (.NET Core 3.0) supports Windows Forms and WPF. But the Visual Studio Designer (and Visual Studio) doesn't support the .NET Core version of Windows Forms and WPF.

Is there any way to make the Visual Studio Designer(and Visual Studio) work with .NET Core 3.0 or Is there any other designer or IDE that I can use to work with .NET Core 3?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

enter image description here

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

  1. Create a Windows Forms .NET Core App. (See the steps and requirements.)
  2. Open the project in Visual Studio and save the the project including solution.
  3. 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.
  4. In properties of the Classic framework project, set default namespace to same default namespace of Core app.
  5. 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:

  1. In the classic framework project, Add New Item
  2. Select Windows Form or User Control
  3. Do some changes in desginer, like resizing the form, so resx file will be generated and Save.
  4. In solution explorer, right click on the form and choose Cut.
  5. In core app, paste all the items.(form, designer, resx).
  6. In the classic app, right click and choose Add Existing Item.
  7. 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
  8. Compile the solution.
  9. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...