WPF:如何从一个窗口,在一个不同的组件开始组件、窗口、不同、WPF

由网友(微微一笑很倾城)分享简介:我GOOGLE了这一点,仍然无法得到它的工作I googled this and still can't get it working我有一个WPF应用程序,并希望从Main.xaml它位于一个不同的组件开始。两个组件都在相同的位置。I have a WPF app and want to start from...

我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 
阅读全文

相关推荐

最新文章