Damien
Damien

Reputation: 2901

Visual Studio Universal App Resource is not found when in Shared folder

This problem is mainly bother some as Visual Studio IDE is telling me that it cant find the resource, but when I build the application I am not having any problem.

In my Visual Studio i have this: enter image description here

Here is an example of my Universal App architecture is as Follows:

Example.windowsPhone

->MainPage.xaml

Example.Share

-> Style.xaml
-> App.Xaml has Style.xaml referenced

Eventhought i have reference DmBlueBrush in my Style Page like this :

 <SolidColorBrush x:Key="DmBlueBrush" Color="{StaticResource DmBlue}" />

In Visual Studio it will tell me that it cant find it, but when I build the application it will find this resource. Have I not reference something correctly for my IDE to work?

I am using Visual Studio 2013 Professional Version 12.0.31101.00 Update 4.

Edit 1:

in App.xaml in Shared i Have:

<Application
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Theme/Styles.xaml"/>
                <ResourceDictionary Source="Theme/Other.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

Upvotes: 7

Views: 829

Answers (2)

sreed
sreed

Reputation: 26

The issue is that you need to merge the ResourceDictionary directly from inside the other ResourceDictionary, instead of including them both in App.xaml.

See here for a complete example: http://blog.craftingbytes.com/2015/05/resource-sharing-in-windows-universal.html

Upvotes: 0

Chubosaurus Software
Chubosaurus Software

Reputation: 8161

Did you link your Resource Dictionary?

Right click Shared Project > Add > New Item > Resource Dictionary

For this example, named it MyStyles.xaml

Then in App.xaml link by

<Application
    x:Class="YOUR_CLASS.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:YOUR_CLASS">
    <Application.Resources>
        <ResourceDictionary Source="MyStyles.xaml"></ResourceDictionary>
    </Application.Resources>
</Application>

example MyStyles.xaml

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:YOUR_CLASS">
    <SolidColorBrush x:Key="MyGreen" Color="Green"/>    
</ResourceDictionary>

Upvotes: 1

Related Questions