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

2 posts, 0 answers
  1. Syed Danish
    Syed Danish avatar
    70 posts
    Member since:
    Dec 2009

    Posted 21 Jun 2010 Link to this post

    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
  2. Dani
    Admin
    Dani avatar
    848 posts

    Posted 23 Jun 2010 Link to this post

    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
  3. DevCraft banner
Back to Top