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?
Starting from Visual Studio 16.5 Preview 1, there is builtin support for Windows Forms designer in Visual Studio. To use the designer:
For more information:
Keep in mind, in this release, many controls aren't yet supported in designer.
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
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:
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.
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 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.
WinForms
project you can refer to this videoHow 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:
WPF
project you can use XAML Designer as below:Reference:
dotnet/samples - WPF Hello World sample with linked files
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:
After setting done, restart vs to take effect.
Now the file structure of the solution is below:
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>
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
.
Now close all opened files. Click the file MainWindow.xaml
of project HiWPF
. Then you can see empty WPF window in XAML designer now.
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:
You can clone it directly to have a look.
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 .
I removed the project files and recreated the project to make it work for me. New -> Project From Existing Code...
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!
Microsoft Visual Studio Professional 2019 版本 16.7.2 开箱即用。
Just found that the instruction to open the file with the WinForms designer is present in the file .csproj.user.
<ItemGroup>
<Compile Update="Form1.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
So, if like me, you have .gitignored this file and have done a git clean, you can't open the file with the Designer anymore.
If the Forms designer is missing. Try adding another Windows Form to your project. Once I did this, the Designer for my other Windows Form appeared.
If you are using Visual Studio 2019, make sure to get the latest update which includes the Windows Form Designer. Some of the earlier version do not include it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.