WPF/XAML Add Item not working in C# Library Shared Project - VS 2022 V17.6.3

Sean Page 0 Reputation points
2023-06-16T19:15:45.87+00:00

I am working on a .net 4.8 c# library project and I am using a Shared Project within it to help with versioning. When I attempt to add a WPF User Control under the shared project, it is not an available template. If I create it under one of the other projects in the solution the option is there and it creates the user control. However, if I then move that user control to the shared project, it splits the xaml and cs files apart and no longer sees that they are connected. This is the same thing if I attempt to add an existing xaml file to the shared project.

I have checked a bunch of the payload stuff in the installer and currently have W10 and W11 SDK also included. Is there something I am just missing here on how to get this to work? I have worked with WFP / XAML stuff in library many times in the past, but never with a shared project.

This image show what it looks like when trying to add to a project.

User's image

You can see in this image that I don't have the same options.

User's image

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,395 questions
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,676 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
766 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Jon M. Snyder 0 Reputation points
    2024-03-17T01:22:41.0766667+00:00

    Hi Sean, were you sucessful with WFP user control in a shared project. I am working on something similar for Revit and am having the same issue. I am able to create the user control, however there is some kind of improper linkage between the code behind and the form, and it seems to be due to it being in a shared project. Did you have any luck in the end with this?

    0 comments No comments

  2. Sean Page 0 Reputation points
    2024-03-17T02:00:40.3333333+00:00

    After moving to a new machine and starting a new shared project in .NET 8 on the current build of VS the WPF behavior has resolved. Now when I create User Controls the code behind is associated as I'd expect. Still suffer from the MSBuild Props, but that is far less of an obstacle. I assume my WPF issue was fixed in an update even if unintentionally. One item to note is that I use a template User Control most the time so its copy and paste, but that wasn't working either previously.

    0 comments No comments