31

Maybe a stupid question, but when I add item to a WPF project, Visual Studio only offers me UserControl, and not Window. Is this trying to encourage me to do MVVM, is my setup broken, or is there some other reason I haven't thought of?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Benjol
  • 63,995
  • 54
  • 186
  • 268

4 Answers4

28

Your project is probably configured as a WinForms project, or possibly as a class library. If it's created as either of these, you are only able to add a WPF UserControl, unfortunately.

Of course, there's no technical reason for this limitation, so you can copy/paste one from another project or recreate/change your project to be a WPF project.

I'm not sure what you change exactly to make it a WPF project in VS's eyes. You might try creating a new project and diffing it to your current project. You will most likely have to do some text editing on your .csproj file.

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
  • 7
    Thanks, I copy-pasted this from another project, and now see the same as you: {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} – Benjol Sep 28 '09 at 05:41
  • 3
    Look at this answer. It details how to add WPF support to an existing project: http://stackoverflow.com/questions/450377/upgrading-a-winforms-app-to-wpf – santiagoIT Sep 13 '13 at 22:03
  • Ultimately, take a look at this: http://www.mztools.com/Articles/2008/MZ2008017.aspx – IAbstract Oct 07 '15 at 16:10
27

Add this to your first <PropertyGroup> element in your csproj:

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

Here's an example:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{24793F93-0FD8-4EC9-B1D2-028DB489B10D}</ProjectGuid>
    <OutputType>WinExe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>nest_spawner</RootNamespace>
    <AssemblyName>nest-spawner</AssemblyName>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>

Becomes:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{24793F93-0FD8-4EC9-B1D2-028DB489B10D}</ProjectGuid>
    <OutputType>WinExe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>nest_spawner</RootNamespace>
    <AssemblyName>nest-spawner</AssemblyName>
    <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>
Warty
  • 7,237
  • 1
  • 31
  • 49
0

Try running devenv /installvstemplates to reset your installed templates. I've used this before when the WPF User Control mysteriously disappeared from my add new list.

In my WPF project, when I click Add I get the following options (which includes Window).

Add New Options

So I'm afraid it's your setup.

Ray
  • 45,695
  • 27
  • 126
  • 169
-3

don't use Visual studio 2015 Microsoft Blend... to open your project.. open your project in Visual Studio - Microsoft Visual Studio ,,, see in title bar