.NET Core的Windows窗体设计器和WPF设计器 [英] Windows Forms Designer and WPF Designer for .NET Core

查看:725
本文介绍了.NET Core的Windows窗体设计器和WPF设计器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近听说.NET Core(.NET Core 3.0)的Alpha版本支持Windows窗体和WPF。但是Visual Studio Designer(和Visual Studio)不支持Windows窗体和WPF的.NET Core版本。是否可以使Visual Studio Designer(和Visual Studio)与.NET Core 3.0一起使用,或者可以与.NET Core 3一起使用的任何其他设计器或IDE?

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?

我问这的主要原因是因为(对我和其他人)使用代码编辑器(如VS Code和Atom)非常困难。

The main reason I am asking this is because it is so hard (for me and others) to use Code-editors (like VS Code and Atom).

我希望这是一个好问题。

I hope that this is a good question.

推荐答案

Windows窗体-可视化Studio 2019(16.5预览版1-.NET CORE 3.1)



从Visual Studio 16.5 Preview 1开始,Visual Studio中内置了对Windows Forms Designer的支持。若要使用设计器:

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:


  • 您必须使用Visual Studio 16.5 Preview 1或更高版本。

  • 您需要在Visual Studio中启用设计器。转到工具→选项→环境→预览功能,然后选择使用.NET Core应用程序的预览Windows窗体设计器选项。

< a href = https://i.stack.imgur.com/iKrpr.png rel = nofollow noreferrer>

更多信息:

  • Updates to .NET Core Windows Forms designer in Visual Studio 16.5 Preview 1.
  • WinForms and WPF .NET CORE repositories.

请记住,在此版本中,设计器中尚不支持许多控件。

Keep in mind, in this release, many controls aren’t yet supported in designer.

从Visual Studio 16.5 Preview 1开始,对Windows Forms Designer的内置支持在Visual Studio中。但是对于较旧的版本,您可以使用以下解决方法:

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:

目前,有一个解决方法,用于将经典.NET Windows Forms Designer用于.NET CORE Windows Forms项目。

At the moment, there is a workaround for using Classic .NET Windows Forms Designer for .NET CORE Windows Forms projects.

解决方法取决于在同一解决方案中具有Classic WinForms应用程序和CORE WinForms应用程序,并且具有相同的根名称空间。

The workaround relies on having Classic WinForms App and CORE WinForms app in the same solution, having the same root namespace.

要添加新的可设计项目,每要添加新项目的时间,您需要将其添加到经典项目中,然后将3个生成的文件(.cs,.designer.cs,.resx)移动到CORE应用中,然后将它们添加为经典应用的链接

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.

要进行编辑,由于它们可以作为经典应用程序中的链接使用,因此请在经典应用程序的设计师中进行编辑。所有更改对CORE应用程序都是可见的。

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.

准备解决方案以将Windows Forms Designer用于.NET Core Winforms App


  1. 创建Windows Forms .NET Core应用程序。 (请参阅步骤和要求。)

  2. 在Visual Studio中打开项目,然后保存项目,包括解决方案。

  3. 右键单击解决方案,然后添加新项目→从模板中选择Windows Forms项目,并将其命名为与Core相同的名称。 app + .Designer,然后单击确定。

  4. 在Classic框架项目的属性中,将默认名称空间设置为与Core应用程序相同的默认名称空间。

  5. 清除两个项目中所有现有的文件并保存更改。

  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.

添加表单或UserControl

每次要添加新表单或用户控件时,都需要执行以下步骤:

Every time which you want to add a new form or user control, you need to do the following steps:


  1. 在经典框架项目中,添加新项

  2. 选择Windows窗体或用户控件

  3. 在设计器中进行一些更改,例如调整表单大小,以便生成resx文件并保存。

  4. 在解决方案资源管理器中,右键单击表单,然后选择剪切。
  5. 在核心应用中,粘贴所有项目。(表单,设计器,resx)。

  6. 在经典应用程序中,右键单击并选择添加现有项。

  7. 浏览打开对话框到核心应用程序文件夹,然后选择添加的这3个文件,然后单击添加按钮附近的下拉菜单,然后选择添加为链接

  8. 编译解决方案。

  9. 使用Mad Kristensen的文件嵌套扩展或通过编辑项目文件来实现。

  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.

现在,每当需要在Core Form或UserControl文件之一上使用Designer时,只需使用Classic Windows Forms Designer在Classic Framework项目中打开链接的文件即可。

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 .NET Core的GA版本设计师被释放与.NET Core 3.0同时提供,并且Visual Studio附带了该版本。

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.

参考

WPF设计器完全独立于Windows窗体设计器。我们在发布.NET Core 3.0的同时发布了其WPF .NET Core Designer的GA版本,该版本随Visual Studio一起提供。在Visual Studio版本16.3.0中,我们存在一个问题,默认情况下,启用XAML设计器属性设置为false。也就是说,当您点击.xaml文件时,设计器不会自动打开。升级到最新的Visual Studio版本16.3.1,修复了此问题。解决该问题的另一种方法是转到工具->选项-> XAML设计器,然后选中启用XAML设计器。

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.

这篇关于.NET Core的Windows窗体设计器和WPF设计器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆