0

In Visual Studio 2019, if I create a new "WPF Application" using .Net Core (top in the screenshot below) it will create a project for me that does in fact include a working XAML setup. However, there is no way that I can find to add a new XAML window through the VS interface. Right-clicking on a folder, choosing Add and then Window (WPF) just gives you the codebehind, no XAML anywhere.

If instead I create a new "WPF App (.NET Framework)" (bottom in the screenshot) It creates a similar project but I can in fact add XAML windows via right-click and selecting Add as above, including the relevant codebehind.

What gives? If we want to use .Net Core do we have to create the XAML files manually? Am I missing something? XAML is explicitly not listed under the .Net Core option, but the project creation process does indeed create XAML files in the project as expected.

enter image description here

2 Answers 2

1

With suggestions above, I was able to get this working in VS2019. To condense the answer:

  1. In the project properties, ensure the "Output Type" is "Windows Application".
  2. Ensure the target framework is ".Net 5.0"
  3. Then directly edit the .csproj file by adding <UseWPF>true</UseWPF> to the first <PropertyGroup>.
  4. Right-click on the project, select: Add > Window
Sign up to request clarification or add additional context in comments.

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker.
0

I seem to have answered my own question but it seems useful so I will leave it up here. When you create your .Net Core WPF Application, if you choose .NetCore 3.1 (Long-term support) you get the behavior I describe above (no ability to add XAML windows). If you choose .NET 5.0 (Current) it works as expected and you can add XAML windows.

7 Comments

What version of VS is this? It seems like a bug.
Could you file a bug here github.com/dotnet/templates?
Also, did you have <UseWPF>true</UseWPF> in your project file?
VS 2019 16.10.1. On my workstation, after creating a couple 5.0 apps yesterday to test, it seems that I can now get a XAML window via right-click and Add when targeting 3.1 as well. Maybe the 5.0 project creation updated something in the background? On my laptop, also having created a couple 5.0 targeted apps to test, I still don't get a XAML window via right-click and Add. Color me bewildered. Should I still create an issue above?
Before creating an issue, can you launch the Visual Studio Installer, then click "Modify" and validate you have the desktop and .NET Core workloads installed? If so, then yes please do file a bug, either on that GitHub repo or via the Report a Problem feature in VS itself.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.