Visual Studio Designer or Some Other Designer for .NET Core 3.0

泪湿孤枕 提交于 2020-01-01 03:40:11

问题


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?

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.


回答1:


Update

Along with GA release of .NET Core 3.0, Windows Forms Designer Preview 1 has also been release.

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

Visual Form Designer is not yet available for Windows Forms and WPF .NET CORE projects. But regarding to their roadmap, designer will be available as part of a Visual Studio 2019 update.

For more information see WinForms and WPF .NET CORE repositories.

Workaround - Using Windows Forms Designer for .NET CORE WinForms Projects

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.




回答2:


For the WinForms project you can refer to this video

How to fix WinForms Designer not support .net core 3.0 visual studio 2019

Since this video give more details we need, we can be followed step by step. It is also based on Microsoft official github project dotnet/winforms

dotnet/winforms - Using the Classic WinForms Designer in WinForms Core

The related code (VS project) made by me is already pushed to github:

.netCore-WinForms_Designer


For the WPF project you can use XAML Designer as below:

Workaround to use the designer in WPF Core App

Reference:

dotnet/samples - WPF Hello World sample with linked files

Install vs 2019 Professional/Enterprise version

Firstly, you need to Install vs 2019 Professional/Enterprise version. Then installing .net core 3.0 SDK is needed. Now you can try to create a .net core WPF application,

After setting the relevant project name and storage path, it will pop up:

Check "Use preview SDK" under .NET core in VS options

After setting done, restart vs to take effect.

Use VS build-in template, create WPF Project named "CoreHiWPF" of .net core

Under the created solution, use VS build-in template to create new WPF project "HiWPF" of .net framework type

Now the file structure of the solution is below:

Update Assembly Name of .net core WPF "CoreHiWPF", make Assembly Names of two projects are the same

Right click the project CoreHiWPF, select Properties, then change its Assembly Name to HiWPF.

Then right click the project, click "Edit CoreHiWPF.csproj".

Add code as below:

  <ItemGroup>
    <ApplicationDefinition Include="..\HiWPF\App.xaml" Link="App.xaml">
      <Generator>MSBuild:Compile</Generator>
    </ApplicationDefinition>
    <Compile Include="..\HiWPF\App.xaml.cs" Link="App.xaml.cs" />
  </ItemGroup>

  <ItemGroup>
    <Page Include="..\HiWPF\MainWindow.xaml" Link="MainWindow.xaml">
      <Generator>MSBuild:Compile</Generator>
    </Page>
    <Compile Include="..\HiWPF\MainWindow.xaml.cs" Link="MainWindow.xaml.cs" />
  </ItemGroup>

Ensure .net core WPF project CoreHiWPF is set as start up project

If the .net core WPF project CoreHiWPF is already highlighted, you can ignore then. Or, you need to select project CoreHiWPF, then right click Set As Start up project.

Try XAML Designer

Now close all opened files. Click the file MainWindow.xaml of project HiWPF. Then you can see empty WPF window in XAML designer now.

Modify the file MainWindow.xaml and related .cs if needed

Then, I add two lines to Grid of the file MainWindow.xaml: - One line is a Label which support Wrap - The other line is a Exit button.

Then I added the Click event to Exit button, added the Loaded event to Window.

After finish updating code, press F5 to run, the final UI is below:

The code is also already pushed to github:

.netCore-WPF_Designer .

You can clone it directly to have a look.




回答3:


If you want to see a preview of your WPF XAML with Visual Studio 2019 just try out this extension https://marketplace.visualstudio.com/items?itemName=GiessweinApps.FAMLDesigner.

It supports .NET Core and .NET Framework:




回答4:


Although the official WPF GitHub Repository states that:

Note: The WPF visual designer is not yet available and will be part of a Visual Studio 2019 update.

There is this example video in which the visual designer is being used.

Hope it helps!



来源:https://stackoverflow.com/questions/53975842/visual-studio-designer-or-some-other-designer-for-net-core-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!