I am using Telerik RadControls for WPF with implicit style. The following style is defined in Themes/Windows8/Telerik.Windows.Controls.RibbonView.xaml :
<Style TargetType="telerikRibbonView:RadRibbonView" x:Key="RadRibbonViewStyle"> ... </Style>
My own styles and default values ββfor Telerik are combined into the Lib.Windows.Controls assembly in the Themes folder:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Windows8/Telerik.Windows.Controls.RibbonView.xaml" /> <ResourceDictionary Source="MyTheme/TelerikCustomizations.xaml" /> <ResourceDictionary> <Style TargetType="{x:Type Rectangle}" /> </ResourceDictionary> </ResourceDictionary.MergedDictionaries> </ResourceDictionary>
And in TelerikCustomizations.xaml I define the following (empty, for testing purposes) style:
<Style x:Key="MyThemeRadRibbonViewStyle" TargetType="{x:Type telerik:RadRibbonView}" BasedOn="{StaticResource ResourceKey=RadRibbonViewStyle}" />
This raises the following exception at runtime:
'Provide value on 'System.Windows.Markup.StaticResourceHolder' threw an exception.' Line number '4' and line position '42'. {"Cannot find resource named 'RadRibbonViewStyle'. Resource names are case sensitive."}
This led me to the following debugging operations in MyView.xaml.cs:
public ShellView() { var baseStyle = FindResource("RadRibbonViewStyle"); var inherited = FindResource("MyThemeRadRibbonViewStyle"); InitializeComponent(); }
Now everything: an exception is thrown in the second FindResource call. With the same message. However, RadRibbonViewStyle explicitly found in the first line of the constructor.
If that matters, the merged dictionary actually merges into App.xaml a second time.
I am sure that I am missing something obvious, but I cannot understand that.
App.xaml
<Application x:Class="TestClient.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="Views/ShellView.xaml"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/Lib.Windows.Controls;component/Themes/MyTheme.xaml" /> <ResourceDictionary> <Style TargetType="{x:Type Rectangle}" /> </ResourceDictionary> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application>
App.xaml.cs does not overwrite the constructor. This actually does nothing.
Update
If I combined Telerik dictionaries in TelerikCustomizations.xaml instead of merging them into another dictionary ( MyTheme.xaml ), the exception will disappear.
However, I would still like to know why this is happening.