2009-09-27 107 views

回答

20

您的項目可能配置爲WinForms項目或可能配置爲類庫。如果它是作爲其中之一創建的,那麼不幸的是,您只能添加WPF UserControl。

當然,這個限制沒有技術上的原因,所以您可以從另一個項目中複製/粘貼一個項目,或者重新創建/更改您的項目爲WPF項目。

我不確定你改變了什麼,使它成爲VS眼中的WPF項目。您可以嘗試創建一個新項目並將其分配到當前項目。您很可能必須在您的.csproj文件上進行文本編輯。

+6

謝謝,我從另一個項目複製粘貼此,現在看到你一樣: {60dc8134-eba5-43b8-bcc9 -bb4bc16c2548}; {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Benjol 2009-09-28 05:41:09

+0

沒問題。別客氣。 – 2009-09-28 07:00:06

+3

看看這個答案。它詳細介紹瞭如何將WPF支持添加到現有項目中:http://stackoverflow.com/questions/450377/upgrading-a-winforms-app-to-wpf – santiagoIT 2013-09-13 22:03:23

0

嘗試運行devenv /installvstemplates重置您安裝的模板。 我之前使用過這個,當WPF用戶控件神祕地從我的添加新列表中消失。

在我的WPF項目中,當我點擊添加時,我得到以下選項(其中包括窗口)。

Add New Options

所以恐怕這是你的設置。

16

在您的csproj添加到您的第一<PropertyGroup>元素:

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

下面是一個例子:

<?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> 

變爲:

<?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> 
+1

好的提示!適用於我 – 2016-01-07 16:34:21

+0

嘗試過,但如果我添加該標記,VS無法加載項目,告訴我「項目名稱相同,已在解決方案中打開」。有任何想法嗎? – 2016-02-05 09:19:44

+0

不適用於我。 – 2016-10-25 06:54:09

0

不使用Visual Studio 2015年微軟混合... 打開你的項目.. 打開你的p roject在Visual Studio - 微軟的Visual Studio ,,, 在標題欄中看到

相關問題