Adding WPF Windows and Pages to existing C# Projects

When working with WPF projects in Visual Studio, you can add WPF Windows, Pages,  User Controls and Resource Dictionaries to a project by right clicking on the project and selecting Add > Window…, Add > Page…,  Add > User Control… or Add > Resource Dictionary… menu options.

The problem I run into is that these menu options are only available if you selected one of the WPF project templates when adding the project to your solution.  How can we add WPF items to existing projects in our solutions?  The solution is similar to my previous post that describes adding workflows to existing projects.

  • Add references to PresentationCore, PresentationFramework, System.Core, System.Data, System.XML, System.Xml.Linq, and WindowsBase to your project. Close Visual Studio and open the csproj file in a text editor. Add the following project type Guids to the PropertyGroup element:

    *   <pre>&lt;ProjectTypeGuids&gt;{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}&lt;/ProjectTypeGuids&gt;</pre>
    
  • Re-open your solution in Visual Studio.  The WPF menu options should now be available for your project.

Adding Workflows to existing C# projects

When working with Workflow projects in Visual Studio, you can add Sequential Workflows, State Machine Workflows, and Activities to a project by right clicking on the project and selecting Add > Sequential Workflow…, Add > State Machine Workflow.., or Add > Activity… menu options.

The problem I run into is that these menu options are only available if you selected one of the Workflow project templates when adding the project to your solution.  How can we add workflows to existing projects in our solutions?  There are a few hoops to jump through to make this happen, but it can be done. 

  • Add references to System.Workflow.Runtime, System.Workflow.Activities, and System.Workflow.ComponentModel to your project. Close Visual Studio and open the csproj file in a text editor. Add the following project type Guids to the PropertyGroup element:
    *   <pre>&lt;ProjectTypeGuids&gt;{14822709-B5A1-4724-98CA-57A101D1B079};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}&lt;/ProjectTypeGuids&gt;</pre>
    
  • Add the following Import to the Project element:
    *   <pre>&lt;Import Project=&quot;$(MSBuildExtensionsPath)\Microsoft\Windows Workflow Foundation\v3.5\Workflow.Targets&quot; /&gt;</pre>
    
  • Re-open your solution in Visual Studio.  The workflow menu options should now be available for your project.