-->

Access ResourceDictionary in Windows Phone project

2020-07-22 16:20发布

问题:

I am creating a Windows Universal 8.1 app. In the Windows Phone 8.1 project inside I have a certain Xaml file as ResourceDictionary. In the Shared Folder I have the common App.xaml of the 2 projects (Windows and Windows Phone).

Path of ResourceDictionary is: "MyApp.WindowsPhone/Assets/Styles/JumpList.xaml"

In App.xaml I add:

<ResourceDictionary>
   <ResourceDictionary.MergedDictionaries>
           <ResourceDictionary Source="MyApp.WindowsPhone/Assets/Styles/JumpList.xaml"/>
   </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

But I am getting:

An error occured while finding the resource dictionary "MyApp.WindowsPhone/Assets/Styles/JumpList.xaml"

Any idea what's wrong in my Path?

回答1:

Since MyApp.WindowsPhone is the root folder you don't need to specify it you can state it as <ResourceDictionary Source="/Assets/Styles/JumpList.xaml"/>
Usually we declare styles inside a new folder named Styles as Assets folder is meant for adding image files according to norms.

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