This is a migrated thread and some comments may be shown as answers.

How to apply Application wide resource dictionary inside a custom control?

1 Answer 625 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Syed Danish
Top achievements
Rank 1
Syed Danish asked on 21 Jun 2010, 03:23 PM
I have resource dictionary declaration inside a Usercontrol like this:

<UserControl.Resources>
        <ResourceDictionary Source="/Phoenix.CAG;Component/Themes/Black.xaml"/>
</UserControl.Resources>


I want to put the resource dictionary only in the App.xaml and let it apply in this usercontrol. Right now I also have this declared inside my app.xaml as

<Application.Resources>
        <ResourceDictionary Source="/Phoenix.CAG;Component/Themes/Black.xaml"/>
</Application.Resources>


 Is there any way to stop repeating the use of the same resource dictionary name in multiple places and put them only in one location and make it work?

Can you please let me know how can I do that?

Regards,
Syed Aalam

1 Answer, 1 is accepted

Sort by
0
Dani
Telerik team
answered on 23 Jun 2010, 09:05 AM
Hi Syed Danish,

From what  I see you are referencing a resource dictionary in a different assemly.

I would suggest that you create a separate Silverlight Class Library which contains a single ResourceDictionary file and then reference this from all other projects that are part of your solution.

Add a reference to the newly created ResourceDictionary as a MergedResourceDictionary in the App.xaml file in each of your projects. For example:

             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             x:Class="Resources_From_Different_Aseembly.App"        
             >
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/MyTheme;component/Generic.xaml" />                 
            </ResourceDictionary.MergedDictionaries>
                </ResourceDictionary>
    </Application.Resources>
</Application>

where Generic.xaml is the new ResourceDictionary.

Styles from Generic.xaml will be applied to all UserControls residing in the projects which reference the custom class library.

I hope this will help you achieve your goal. Please, write back in case you need further help.

Best wishes,
Dani
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Syed Danish
Top achievements
Rank 1
Answers by
Dani
Telerik team
Share this question
or