Hi,
I am trying to load ResourceDictionary at runtime by adding it to MergedDictionaries. My ResourceDictionaries are defined as follows (see bwlow) - but for some reason I can seem get a reference to it to add to MergedDictionaries. What am I doing wrong?
<ResourceDictionary> <ResourceDictionary x:Key="igThemePivotGrid" x:Name="igThemePivotGrid" Source="Styles/IgTheme/IG.xamPivotGrid.xaml"/> <ResourceDictionary x:Key="office2010BlueThemePivotGrid" x:Name="office2010BlueThemePivotGrid" Source="Styles/OfficeBlueTheme/Office2010Blue.xamPivotGrid.xaml"/> </ResourceDictionary>
Thanks
Sangeetha
In code behind, I can do it as follows and it works fine. It would be nice to know how to do it via Xaml designer.
ResourceDictionary dict = new ResourceDictionary();
dict.Source = new Uri("/MarketManipulatorControl;component/Styles/IgTheme/IG.xamPivotGrid.xaml", UriKind.RelativeOrAbsolute);Application.Current.Resources.MergedDictionaries.Add(dict);
Hello,
You have to remove x:Key from the resource dictionary definition.
Plamen.
Hi Plamen,
Sorry it is not clear. I figured out my problem. My ResourceDictionary was defined at the UserControl level while I was looking for the dictionary at the Application.Current.Resources level.
Here is my xaml
<UserControl.Resources> <ResourceDictionary> <ResourceDictionary x:Key="igThemePivotGrid" x:Name="igThemePivotGrid" Source="/MarketManipulatorControl;component/Styles/IgTheme/IG.xamPivotGrid.xaml"/> <ResourceDictionary x:Key="office2010BlueThemePivotGrid" x:Name="office2010BlueThemePivotGrid" Source="/MarketManipulatorControl;component/Styles/OfficeBlueTheme/Office2010Blue.xamPivotGrid.xaml"/> <ResourceDictionary.MergedDictionaries> <ResourceDictionary x:Name="styles" Source="Styles/Styles.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </UserControl.Resources>
That's why I wanted to see more of your code. It still is not much clear.
My ResourceDictionary is outside <ResourceDictionary.MergedDictionaries>.
Having x:Key in the dictionary produces this error for me
Could you provide a snippet with the code that wraps your ResourceDictionary. My code is located into App.xaml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Theme.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Thank You for your reply.
My designer requires me to enter a key as I have more than one dictionary.
Also, the altanative of using uri seems to have some bug. I followed the silverlight sample below.
http://samples.infragistics.com/sldv/RunSamples.aspx?cn=pivot-grid#/pivot-grid/theming
but when I iterate through the list mosre than one, it throws the following error at
Application.Current.Resources.MergedDictionaries.Add(...);
The invoked member is not supported.