【发布时间】:2019-08-09 04:00:22
【问题描述】:
下面是我的解决方案树,你可以看到,App.xaml 在 G_Hoover.Init 项目中,BrowserView.xaml 窗口在 G_Hoover.Views 项目中.
我想弄清楚如何在App.xaml 中定义StartupUri,即BrowserView.xaml 将是一个启动窗口。
我找到is here的唯一方法,但是当我输入App.xaml时:
StartupUri="C:/Users/asus/Desktop/IT/Programowanie/Projekty/G_Hoover/G_Hoover.Views/BrowserView.xaml"
我收到一个异常:
XamlObjectWriterException:指定的类名 'G_Hoover.Views.BrowserView' 与实际根实例类型不匹配 'System.Windows.Window'。删除 Class 指令或提供 通过 XamlObjectWriterSettings.RootObjectInstance 实例。
当我输入时:
StartupUri="pack://application:,,,/G_Hoover;G_Hoover.Views/BrowserView.xaml">
我收到异常:
System.IO.IOException: '找不到资源 'g_hoover;g_hoover.views/browserview.xaml'。'
当我根据this approach 输入App.xaml.cs 时,我得到的结果相同:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
StartupUri = new Uri("pack://application:,,,/" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ";G_Hoover.Views/BrowserView.xaml", UriKind.RelativeOrAbsolute);
//or this: StartupUri = new Uri("pack://application:,,,/G_Hoover;G_Hoover.Views/BrowserView.xaml", UriKind.RelativeOrAbsolute);
//or this: StartupUri = new Uri("C:/Users/asus/Desktop/IT/Programowanie/Projekty/G_Hoover/G_Hoover.Views/BrowserView.xaml");
}
}
请注意,G_Hoover.Init 引用了 G_Hoover.Views。我做错了什么?
【问题讨论】: