ResourceDictionary Source 中的 Uri 语法(通用 Windows 平台) [英] Uri syntax in ResourceDictionary Source (Universal Windows Platform)

查看:33
本文介绍了ResourceDictionary Source 中的 Uri 语法(通用 Windows 平台)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的 Windows 8.1 项目迁移到 Windows 10(通用 Windows 平台).此时我被 UWP 中的 ResourceDictionary 更改阻止了.

I'm migrating my Windows 8.1 projects to Windows 10 (Universal Windows Platform). At this moment I was stopped by ResourceDictionary changes in UWP.

为简单起见:我有 2 个项目的 Windows 8.1 解决方案:

For simplicity: I have Windows 8.1 solution with 2 projects:

App project (FooApp)+ Styles (FooStyles) project.

FooApp 引用了 FooStyles,在 App.xaml 中我有:

FooApp has reference to FooStyles, and in App.xaml I have:

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

ms-appx 语法允许我从其他项目访问资源文件.现在在 Windows 10 应用程序中,这不再起作用.编译以以下错误结束:

ms-appx syntax allowed me to access resource files from other projects. Now in Windows 10 apps this is not working anymore. Compilation ends with the below error:

"An error occurred while finding the resource dictionary "ms-appx:///FooStyles/Brushes.xaml"."

这里有什么建议可以解决吗?

Any advices here, to fix it?

P.S 我不会将我的资源从 FooStyles 移动到 FooApp,因为在我的解决方案中,FooStyles 在其他 5 个应用程序项目之间共享.

P.S I would not move my resources from FooStyles to FooApp, because in my solution, FooStyles is shared between 5 other app projects.

推荐答案

在 UWP 中,您必须指定命名空间才能实现此目的.此外,我发现 XAML 资源词典仅在属性"部分中标记为页面"时才以这种方式引用.

In UWP you must specify the namespace to achieve this. Also, I've found XAML Resource Dictionaries only reference this way if they are marked "Page" in the Property section.

然后在您的应用程序 xaml 中:

Then in your Application xaml:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="ms-appx:///Default.Namespace.External.Assembly/FolderPathOffRoot/Brushes.xaml"/>
        </Application.Resources>
    </ResourceDictionary>
</ResourceDictionary.MergedDictionaries>

不要对 ms-appx 感到困惑,它指的是您的包,而不仅仅是包含应用程序的项目.

And don't be confused about ms-appx, it refers to your package, not just the project containing the application.

这篇关于ResourceDictionary Source 中的 Uri 语法(通用 Windows 平台)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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