WPF:如何从不同程序集中的窗口启动
我用谷歌搜索了这个,仍然无法让它工作
我有一个 WPF 应用程序,想要从位于不同程序集中的 Main.xaml 开始。两个组件都位于同一位置。
我该怎么做?我从 XAML 中取出 StartupUri 并尝试使用这些和一些细微的变化:
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
StartupUri = new Uri("/CompanyName.VisualStudio.UI;CompanyName/VisualStudio/UI/DatabaseManager/Main.xaml", UriKind.Relative);
//StartupUri = new Uri(@"pack://application:,,,/ CompanyName.VisualStudio.UI;CompanyName/VisualStudio/UI/DatabaseManager/Main.xaml");
}
程序集的名称是“CompanyName.VisualStudio.UI”,命名空间是“CompanyName/VisualStudio/UI/DatabaseManager/Main.xaml”
有什么想法吗?
I googled this and still can't get it working
I have a WPF app and want to start from Main.xaml which is located in a different assembly. Both assemblies are in the same location.
How can I do this? I took out the StartupUri from the XAML and tried with these and some slight variations:
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
StartupUri = new Uri("/CompanyName.VisualStudio.UI;CompanyName/VisualStudio/UI/DatabaseManager/Main.xaml", UriKind.Relative);
//StartupUri = new Uri(@"pack://application:,,,/ CompanyName.VisualStudio.UI;CompanyName/VisualStudio/UI/DatabaseManager/Main.xaml");
}
The name of the assembly is "CompanyName.VisualStudio.UI" and the namespace is "CompanyName/VisualStudio/UI/DatabaseManager/Main.xaml"
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
本文提供了一个干净的仅 XAML 解决方案。
其中:
示例:
This article gives a clean XAML-only solution.
Where:
Examples:
我会检查你的包 URI。下面是我尝试的 uri。将“组件”视为项目中的根文件夹,在我放置“FolderName”的位置放置适当的文件夹名称,或者如果 Main.xaml 位于项目的根目录中,则将其删除。
StartupUri = new Uri(@"pack://application:,,,/CompanyName.VisualStudio.UI;component/FolderName/Main.xaml", UriKind.Absolute);
I'd check your pack URI. Below is the uri I'd try. Think of 'component' as the root folder in your project and where I've put 'FolderName' put the appropriate folder name or remove it if Main.xaml is in the root of the project.
StartupUri = new Uri(@"pack://application:,,,/CompanyName.VisualStudio.UI;component/FolderName/Main.xaml", UriKind.Absolute);
老问题,但是这个也很有帮助:
我的 app.xaml:
并记住 ShutdownMode :如果您记得在关闭最后一个窗口之前打开新窗口,您应该会很好
Old question, but this is also helpful:
and i app.xaml:
and rememeber about ShutdownMode : if you remember to open new window before closing last one you should be good