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

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

问题描述

我最近听说 .NET Core (.NET Core 3.0) 的 alpha 版本支持 Windows Forms 和 WPF.但是 Visual Studio 设计器(和 Visual Studio)不支持 .NET Core 版本的 Windows 窗体和 WPF.

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.

有什么方法可以让 Visual Studio 设计器(和 Visual Studio)与 .NET Core 3.0 一起工作,或者有没有其他设计器或 IDE 可以与 .NET Core 3 一起工作?

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?

推荐答案

Windows Forms - Visual Studio 2019 (16.5 Preview 1 - .NET CORE 3.1)

从 Visual Studio 16.5 Preview 1 开始,Visual Studio 内置了对 Windows 窗体设计器的支持.使用设计器:

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 窗体设计器选项.

更多信息:

  • 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 开始,Visual Studio 内置了对 Windows 窗体设计器的支持.但是对于旧版本,您可以使用以下解决方法:

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 窗体设计器用于 .NET CORE Windows 窗体项目.

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

解决方法依赖于在同一解决方案中使用经典 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 for .NET Core Winforms App 的解决方案

  1. 创建一个 Windows 窗体 .NET Core 应用程序.(查看步骤和要求.)
  2. 在 Visual Studio 中打开项目并保存包含解决方案的项目.
  3. 右键单击解决方案并添加新项目 → 从模板中,选择 Windows 窗体项目,并将其命名为与核心应用程序相同的名称 +.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.

添加表单或用户控件

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

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.

现在,只要您需要在核心窗体或用户控件文件之一上使用设计器,只需使用经典 Windows 窗体设计器打开经典框架项目中的链接文件即可.

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 Designer 的 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天全站免登陆