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

Applying Custom Theme Error

1 Answer 56 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tom Kenny
Top achievements
Rank 1
Tom Kenny asked on 04 Aug 2010, 09:16 PM
I have created a custom theme but when applying it to the applicaiton that we are currently developing it throws an error only visible within the Firefox error console.

Error: Unhandled Error in Silverlight Application
Code: 2272   
Category: ParserError      
Message: Cannot find a Resource with the Name/Key BtnChrm    
File:     
Line: 81    
Position: 61    
 
Source File: http://localhost:4498/CustomThemeTestTestPage.aspx
Line: 56

 I was able to narrow it down with by creating a sample project, and it seems that the error is only ever thrown when the resource dictionary in the App.xaml requires a key.

This dosn't work~
<Application.Resources>
    <ResourceDictionary>
           <ResourceDictionary  x:Key="test" Source="/CustomTheme;component/Themes/CustomThemeGeneric.xaml"/>
    </ResourceDictionary>
</Application.Resources>
But this does~
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/CustomTheme;component/Themes/CustomThemeGeneric.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

Thing is within our main app, there are other items within the application recources so no matter what the resource dictionary for the custom theme requires a key. So my question is what other changes do I have to make to apply the custom theme if the resource dictionary requires a key.

Also this custom theme is being applied application wide within the App.xaml.cs using:
Telerik.Windows.Controls.Theme appTheme = new CustomTheme.CustomTheme();
Telerik.Windows.Controls.StyleManager.ApplicationTheme = appTheme;

Thanks in advance!
Tom.

1 Answer, 1 is accepted

Sort by
0
Dani
Telerik team
answered on 06 Aug 2010, 12:04 PM
Hi Tom Kenny,

Thank you for your inquiry and for your detailed explanation.

By default, when you want to place a Resource Dictionary within another Resource Dictionary, you must do that by using Merged Resource Dictionaries. Therefore, it is only natural that the code snippet which you point as non- working is indeed wrong.

Moreover, when you add an item to a resource dictionary,  it should have a key (of course, except the cases where styles and control templates have a target type only).

Please, correct me if I am wrong, but I can judge from your post, that you have a custom theme on one hand and a few other resources on the other hand. I suggest that you keep those both in separate resource dictionary files and merge them with MergedDictionary inside App.xaml ,or better still, in a third Resource Dictionary file.

I hope this information is going to be helpful. Please, contact us again if you need further help.


Regards,
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
Tom Kenny
Top achievements
Rank 1
Answers by
Dani
Telerik team
Share this question
or