Uri syntax in ResourceDictionary Source (Universal Windows Platform)

折月煮酒 提交于 2019-12-07 11:06:59

问题


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.

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

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

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 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 I would not move my resources from FooStyles to FooApp, because in my solution, FooStyles is shared between 5 other app projects.


回答1:


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.

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>

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



来源:https://stackoverflow.com/questions/33033971/uri-syntax-in-resourcedictionary-source-universal-windows-platform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!