Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add WPF templates to a class library project

I have a class library that is going to have some WPF UI. I've got the framework plugged in. Is there a way I can incorporate the "Add Item" WPF templates? As of now, I only have UserControl. I can create the files myself, but it would save me a lot of time to be able to add them in the IDE.

Thanks.

like image 758
Jordan Avatar asked Sep 03 '15 18:09

Jordan


People also ask

How do I add a class library to an existing project?

Right Click on Project--> Add--> New Project-->click on Class Library. Now your class library is created as class1. cs . Right Click on References (of your program/console app).

How do I import a class library into Visual Studio?

If you are using Visual Studio, click "Project->Add Reference.." and select the tab "Browse". Now in the file browser, select the output file of your Class Library(. dll). Now you should be able to explore the class of your library in "Class View".


1 Answers

A bit late but:

.NET projects have zero or more project types in the csproj file that enable/disable IDE features.

If you started from a class library and want to change it as if it were a WPF control library, you can just add these project types manually to the csproj file.

Add the <ProjectTypes> element as shown below to the <PropertyGroup> that also contains the <ProjectGuid>:

<Project ...>
  <ProjectGroup ...>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{64D2C408-BB81-4627-AF7C-672142229677}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Some.Client.WPFLib</RootNamespace>
    <AssemblyName>Some.Client.WPFLib</AssemblyName>
    <TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>

    <!-- add this line: -->
    <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

    <SccProjectName>SAK</SccProjectName>
    <SccLocalPath>SAK</SccLocalPath>
    <SccAuxPath>SAK</SccAuxPath>
    <SccProvider>SAK</SccProvider>
  </ProjectGroup>
</Project>

These two guids are what you find in a WPF Application project and represent ProjectTypes "Windows C#" and "WPF". (http://www.codeproject.com/Reference/720512/List-of-Visual-Studio-Project-Type-GUIDs)

like image 186
Thomas Avatar answered Oct 09 '22 16:10

Thomas