Windows 10 通用合并词典 [英] Windows 10 Universal Merged Dictionaries

查看:21
本文介绍了Windows 10 通用合并词典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个 Windows 通用类库,其中有一个资源字典,我想将它与 App.xaml 中的 Windows 10 通用应用程序的主要资源字典合并.

我的 App.xaml 只是从同一个程序集中合并到我的主资源字典中.

<资源字典><ResourceDictionary.MergedDictionaries><ResourceDictionary Source="Styles/Styles.xaml"/></ResourceDictionary.MergedDictionaries></ResourceDictionary></Application.Resources>

然后从我的主资源字典 (Styles/Styles.xaml) 中,我正在合并来自同一程序集的其他资源字典.这是我想从另一个程序集合并资源字典的地方:

<ResourceDictionary Source="Fields.xaml"/><ResourceDictionary Source="DataTemplates.xaml"/><!--<ResourceDictionary Source="/{AssemblyName};component/Shared.xaml"/>--><!--<ResourceDictionary Source="pack://application:,,,/{AssemblyName};component/Shared.xaml"/>--><ResourceDictionary Source="ms-appx:///{AssemblyName}/Shared.xaml"/></ResourceDictionary.MergedDictionaries>

我尝试将其添加到我的主要资源字典中:

还有这个...

基于

So I have a Windows Universal Class Library that has a resource dictionary in it that I want to merge with my Windows 10 Universal Application's main resource dictionary in App.xaml.

My App.xaml simply merges in my main Resource dictionary from the same assembly.

<Application.Resources>
    <ResourceDictionary>

        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Styles/Styles.xaml"/>
        </ResourceDictionary.MergedDictionaries>

    </ResourceDictionary>
</Application.Resources>

Then from my main resource dictionary (Styles/Styles.xaml) I am merging in other resource dictionaries from the same assembly. This is where I would like to merge in a resource dictionary from another assembly:

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Fields.xaml"/>
    <ResourceDictionary Source="DataTemplates.xaml"/>
    <!--<ResourceDictionary Source="/{AssemblyName};component/Shared.xaml" />-->
    <!--<ResourceDictionary Source="pack://application:,,,/{AssemblyName};component/Shared.xaml" />-->
    <ResourceDictionary Source="ms-appx:///{AssemblyName}/Shared.xaml" />
</ResourceDictionary.MergedDictionaries>

I've tried adding this to my main resource dictionary:

<ResourceDictionary Source="/{AssemblyName};component/Shared.xaml" />

and this...

<ResourceDictionary Source="ms-appx:///{AssemblyName}/Shared.xaml" />

Based on this article about Windows 8.x Store Apps this seems like how it should work. But it still doesn't work.

and this...

<ResourceDictionary Source="pack://application:,,,/{AssemblyName};component/Shared.xaml" />

(this is the WPF way, I know, but I thought I would give it a try anyway!)

But none seem to work...

The build action of the resource dictionaries that I have in my application assembly are set to 'Page'. These resource dictionaries are working simply using this in the merge:

<ResourceDictionary Source="Styles/Styles.xaml"/>

I get the following cryptic error:

Failed to assign to property 'Windows.UI.Xaml.ResourceDictionary.Source' because the type 'Windows.Foundation.String' cannot be assigned to the type 'Windows.Foundation.Uri'. [Line: 12 Position: 37]

解决方案

As Romasz mentioned in comment, you need to reference the project which including the styles. And then using the following code to reference.

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="ms-appx:///UserControlLibs/Styles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

这篇关于Windows 10 通用合并词典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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