WPF:如何从一个窗口,在一个不同的组件开始 [英] WPF: How to start from a window in a different assembly
问题描述
我GOOGLE了这一点,仍然无法得到它的工作
I googled this and still can't get it working
我有一个WPF应用程序,并希望从Main.xaml它位于一个不同的组件开始。两个组件都在相同的位置。
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.
我怎样才能做到这一点?我拿出的StartupUri从XAML,并试图与这些和一些轻微的变化:
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");
}
程序集的名称是CompanyName.VisualStudio.UI和命名空间是公司名称/ VisualStudio中/ UI /的DatabaseManager / Main.xaml
The name of the assembly is "CompanyName.VisualStudio.UI" and the namespace is "CompanyName/VisualStudio/UI/DatabaseManager/Main.xaml"
任何想法?
推荐答案
本文给出了一个干净的XAML,唯一的解决方案。
This article gives a clean XAML-only solution.
StartupUri="pack://application:,,,/assembly_name;component/path/file_name.xaml"
其中:
- assembly_name是引用的程序集的名称,SANS扩展
- 路径是在该组件所在的子文件夹;如果该组件是在项目的根,省略此元素
- file_name是组件 的文件名
例如:
pack://application:,,,/UI;component/CalculatorView.xaml
assembly - UI.dll
path - none (file at project root)
file_name - CalculatorView
pack://application:,,,/MyApp.UI;component/Views/CalculatorView.xaml
assembly - MyApp.UI.dll
path - Views
file_name - CalculatorView
pack://application:,,,/UI;component/Views/External/CalculatorView.xaml assembly - UI.dll
path - Views/External
file_name - CalculatorView
这篇关于WPF:如何从一个窗口,在一个不同的组件开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!