将WPF XAML资源添加到DLL [英] Add a WPF XAML resourcedictionary to a DLL

查看:282
本文介绍了将WPF XAML资源添加到DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我误会了这一切如何工作,你不能真正将一般的旧XAML文件作为数据,将其作为可以被抢走的数据,但是我认为这是可能的。

Maybe I'm misunderstanding how this all works and you can't really stuff plain old XAML files into a DLL as data which can be grabbed out later - but I thought this was possible.

我已经反复尝试了五个小时,让它工作,所以我终于要求Stack Overflow。

I have tried over and over and over again for like five hours to get this to work so I'm finally asking Stack Overflow.

我在WPF用户控制库项目中有一个XAML文件。在完美的世界中,我应该能够将这个XAML文件以某种方式嵌入到DLL中以供另一个项目参考。我不想链接到原始项目文件夹或任何类似的东西,如果可能只是为了保持一切美好和简单,在一个地方。

I have a XAML file in a WPF User Control Library project. In a perfect world, I should be able to have this XAML file embedded in some way into the DLL for reference in another project. I don't want to link to the original project folder or anything like that if possible just to keep everything nice and simple and in one place.

所以这里是问题这是绊倒了我:

So here are the questions that are tripping me up:


  1. 如果您在项目中编译一个文件的DLL,编译模式设置为资源 - 该文件是否实际上被填充到DLL中?如果没有 - 有办法吗?

  1. If you compile a DLL with a file in the project that's compile mode is set to "resource" - does that file actually get stuffed into the DLL? If it doesn't - is there a way to do that?

说我的资源文件在类库项目中被修改:

Say my resource file is pathed as such in the Class Library project:

MyClassLibrarySolutionRoot / StyleXAMLs / Styles.xaml

"MyClassLibrarySolutionRoot/StyleXAMLs/Styles.xaml"

放在应用程序文件中的URI路径:

What do I put for the URI path in the application file:

     <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="What on earth am I supposed to put here?"></ResourceDictionary>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

提前感谢! FYI这个特别的问题使我有点吝啬试图学习XAML,因为无法使其工作,真正打破了我喜欢的工作流程,基本上将基本应用程序的代码抛弃到类库中。所以,也许你可以恢复我对XAML的信仰,确保我仍然可以轻松使用和引用DLL?

Thanks in advance! FYI this particular problem has made me a bit batty regarding trying to learn XAML because failure to make it work really breaks the workflow I like to have by basically throwing absolutely everything except the base application's code into class libraries. So, maybe you can restore my faith in XAML by assuring me I can still easily use and reference DLLs?

PS ...我已经尝试了这个确切的URI格式一遍又一遍,它不起作用:pack:// application:,,, / externalDllName; component / path / dictionary.xaml

PS... I have tried this exact format for the URI over and over and it doesn't work: pack://application:,,,/externalDllName;component/path/dictionary.xaml

组件是否应该是单词组件,还是应该像ResourceDictionary这样的东西?这个路径应该是原始DLL项目中的文件夹的名称还是别的?

Is "component" supposed to be the word "component" or is it supposed to be something else like "ResourceDictionary"? Is that "path" supposed to be the names of the folders in the original DLL project or something else?

这里,我决定添加一张照片,因为我不知道我做错了什么:

Here, I decided to include a picture because I have no idea what I'm doing wrong:

推荐答案

嗯,听起来很愚蠢,我没有仔细看,终于发现它是扔了在类库的完全不同部分的URI上解析错误。

Well, as foolish as it may sound I wasn't looking carefully enough and finally discovered that it was throwing a parse error on a URI on a completely different part of the class library.

导致我被误导的是试图将资源添加到App.xaml中。 IDE不断给我错误程序集没有被这个项目引用,导致我相信解析错误是由于带有底层错误的URI的结果,我甚至没有停止认为它是C#代码中的URI在分类图书馆里,抛出了解析错误。

What caused me to be misled was trying to add a the resourcedictionary to App.xaml. The IDE kept giving me the error "Assembly is not referenced by this project" leading me to believe the parse error was a result of the URI with the underlying error and I didn't even stop to consider that it was a URI in C# code in the class library that was throwing the parse error.

对不起,浪费了这里的人的时间 - 但要学习的小课程如下:

Sorry to have wasted the time of people here - but the small lesson to be learned is the following:

当试图引用XAML代码中的外部程序集时,Visual Studio将偶尔会发生错误的错误,这可能会导致您查看错误的部分以进行解析异常。 >

Visual Studio will occasionally give erroneous errors when trying to reference an external assembly in XAML code which may lead you to look at the wrong part for your parse exception.

这篇关于将WPF XAML资源添加到DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆