Workaround to use the designer in WPF Core App (.netCore WPF).
CoreHiWPF: An executable WPF Core application project, need to open with Visual Studio 2019.
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.
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:
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 pushed to github:
Reference: