How can I add WPF items into a c# class library project in VS2019

夙愿已清 提交于 2020-05-11 07:36:33

问题


I have started a Class library project in Visual Studio 2019 and now wish to add WPF items (Window, user control, custom control) into it, but the 'Add Item' dialogue box doesn't list anything under the WPF section. I have come across this problem in previous versions of VS and managed to get round it by adding the element into the csproj file with the relevant WPF guids, however that doesn't appear to work with the new VS2019 stripped down csproj file, or I don't know where to find the correct GUIDs (as I have only tried using those I used before).

Does anyone know the correct process to follow for VS2019?

P.S. I am aware that this question appears to have been answered before (for example No creation of a WPF window in a DLL project) but as far as I can tell they are all for previous versions of Visual Studio and the suggestions don't work for me.


回答1:


Right-click on the class library project, choose "Edit project file" and copy the following contents into the .csproj file:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

</Project>

This should give you the ability to add WPF specific items to the project using the menus.



来源:https://stackoverflow.com/questions/58836149/how-can-i-add-wpf-items-into-a-c-sharp-class-library-project-in-vs2019

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!