问题
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