为什么 Visual Studio 不希望我向 WPF 项目添加新窗口? [英] Why doesn't Visual Studio want me to add a new window to my WPF project?
问题描述
也许是一个愚蠢的问题,但是当我向 WPF 项目添加项目时,Visual Studio 只为我提供 UserControl,而不是 Window.这是在鼓励我做 MVVM,是我的设置坏了,还是有其他我没有想到的原因?
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?
推荐答案
您的项目可能配置为 WinForms 项目,或者可能配置为类库.不幸的是,如果它是作为其中任何一个创建的,则您只能添加 WPF UserControl.
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.
当然,此限制没有技术原因,因此您可以从另一个项目复制/粘贴一个,或者重新创建/将您的项目更改为 WPF 项目.
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.
我不确定在 VS 眼中您究竟做了什么更改以使其成为 WPF 项目.您可以尝试创建一个新项目并将其与当前项目进行比较.您很可能需要对 .csproj
文件进行一些文本编辑.
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.
这篇关于为什么 Visual Studio 不希望我向 WPF 项目添加新窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!