wpf 如何在 App.Xaml StartUpUri 中设置视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18452425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 09:30:25  来源:igfitidea点击:

How to set a View in App.Xaml StartUpUri

wpfxamlmvvm

提问by WpfBee

I have created one MVVM sample application. My solution structure is like I have 4 folders. 1st for Model, 2nd for View, 3rd for ViewModel, and 4th for HelperClasses. Currently I have only one view in View folder. I want to set my view [say FamilyView, present in View folder] in StartupUri in App.xaml file, which is by default set to MainWindow.xaml.

我创建了一个 MVVM 示例应用程序。我的解决方案结构就像我有 4 个文件夹。Model 1st,View 2nd,ViewModel 3rd,HelperClasses 4th。目前我在 View 文件夹中只有一个视图。我想在 App.xaml 文件的 StartupUri 中设置我的视图 [比如 FamilyView,存在于视图文件夹中],默认情况下设置为 MainWindow.xaml。

I don't want to set the startup in App.Xaml.cs.

我不想在 App.Xaml.cs 中设置启动。

Please suggest how to do that?

请建议如何做到这一点?

Also, can you please suggest how to change view in App.Xaml file only, if having more than one view.

另外,如果有多个视图,您能否建议如何仅在 App.Xaml 文件中更改视图。

回答by Sherlock

I'm not exactly sure what you're asking. If your StartupUri is in another namespace then you have to specify which namespace it is in like this

我不确定你在问什么。如果您的 StartupUri 在另一个命名空间中,那么您必须像这样指定它在哪个命名空间中

StartupUri="Windows\LoginWindow.xaml">

You go on to say that you don't want to set the StartupUri in App.xaml. You can do this programmatically by overriding the OnStartup method. Take a look at this linkfor more details.

您继续说您不想在 App.xaml 中设置 StartupUri。您可以通过覆盖 OnStartup 方法以编程方式执行此操作。请查看此链接以了解更多详细信息。