1

In Visual Studio 2022, I can create a WPF form in my C# Project (Masterclass.Revit.2023) but when I copy or move it to my Shared Project within the same solution it splits the .xaml into two separate files and the window is no longer visible. What I mean is the .cs file is no longer a subfile of the .xaml file, they are seen as two separate files. Furthermore, when I was following Konrad Sobon in a youtube video @ timestamp (2:37:17 video link is below) he can do it just fine and when I clone his file from GitHub it works just fine.

SHARED PROJECT IMAGE

BadMoneys|AEC Tech 2021 https://www.youtube.com/watch?v=iS_d90bq6k0&t=7687s

Cloned File https://github.com/TheBIMsider/Masterclass

I tried creating the WPF user control form from my Shared Project its still spilts it into two files and as I said before I can create it in a C# Project it works like it should and the .cs file is a sub file of the .xaml file.

How can I get this form to be visible inside my Shared Project and the .cs file be a subfile of the .xaml file?

  • It's not splitting the one file. They are two separate files, visual studio just displays them together. Just drag drop the cs file as well. – Andy Apr 21 '23 at 17:20
  • New style csproj don't have a list of files within em. If you're still confused you could look in file explorer and move the two files. In this case you would then probably also want to change the namespace to match where you moved them to. – Andy Apr 21 '23 at 17:22
  • I still get an invalid markup in my .xaml preview window – Christopher Bowker Apr 21 '23 at 19:39
  • The xaml refers to the class defined by the cs file. Maybe you haven't changed the namespace there. – Andy Apr 22 '23 at 10:45

1 Answers1

0

This may not be the best solution, but you can create a new blank WPF File (Window or UserControl will not matter) in your Shared Project, This will create 2 Files, XAML with its sub-file .cs. Open the XAML Files in your Old project and in your Shared Project, Copy All XAML Lines from Old to Shared, then Open the .cs File in your Old and Shared Project, and Copy all lines from old to shared. Finally, check your namespaces in the shared project.

This should solve your issue.

  • 1
    Thanks, Mostafa; I will be sure to check it out and let you know the outcome. – Christopher Bowker Apr 28 '23 at 00:05
  • 1
    I guess that kind of worked, plus I added a bunch of references for the WPF to each of my Projects inside my share floder, like system.xmal, windowsbase, and PresentationCore and another one or two. – Christopher Bowker Apr 28 '23 at 23:14