Forgive me if this question is answered already or documented elsewhere, but I have yet to find an answer.
Backstory:
I'm using the IG theme in my application. I wish to make a very small modification to the XamComboEditor template. I have found the template for it in "C:\Program Files (x86)\Infragistics\2015.1\WPF\Themes\IG\IG.xamComboEditor.xaml". Upon copying the template into my application for some modifications I get build errors on the brushes and colors used by the template.
Now, I know I can just copy the necessary xaml files into my application and reference them via a MergedDictionary, but I can't help but feel that there is a more elegant solution.
Now, I have a class library with some controls and shared styles in it. In order to use that in my primary application, I merely add the following at the top of my user control.
<ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/CommonLibrary;component/Themes/CommonStyles.xaml" /> </ResourceDictionary.MergedDictionaries>
My question is, is this possible with the IG DLLs? My attempts at it have failed thus far. Is there perhaps a more elegant solution?
Here's what I'm hoping to do in order to get access to the brushes and colors for the theme:
<ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/CommonLibrary;component/Themes/CommonStyles.xaml" /> <ResourceDictionary Source="/InfragisticsWPF4.Themes.IG.v15.1;component/Themes/IG/Styles.Shared.xaml" /> </ResourceDictionary.MergedDictionaries>
Or do I need to do something like the following?
<ResourceDictionary Source="pack://application:,,,/InfragisticsWPF4.Themes.IG.v15.1;component/Themes/IG/Styles.Shared.xaml" />
Is there a way to do it that is agnostic of the version? Or does the version utility find and upgrade such lines?
Konstnatin,
Thankfully I was already applying the ThemeManager correctly to the entire application. Now your solution did the trick at helping me figure out the rest!
For documentation purposes:
With respect to overriding a particular ControlTemplate, there were errors present because it couldn't find the specific Colors and Brushes with the StaticResource references found in the template as it was defined when I copied it from IG.xamComboEditor.xaml. I wanted to use those colors and I wanted to do it in a way that was easily maintainable as version upgrades came out.
Here's what I tired:
The first was that worked, but wasn't ideal was: From my target theme, copy Styles.Shared.xaml, Styles.WPF.xaml, and Theme.Colors.xaml into my project and reference them. This isn't ideal because then if those styles are modified in a future release, I'll have to remember to copy them over as part of the build process.
The second way which I didn't get working was to try something like:<ResourceDictionary Source="/InfragisticsWPF4.Themes.IG.v15.1;component/Themes/Styles.WPF.xaml" />I still don't know if its possible, but it wasn't ideal because it locked me into the version # and I don't know if the upgrade utility would catch something like that. If there was a way to do that without specifying the version number, then it would be the ideal solution.
The third that worked was your way. I REALLY like how generic it is and how it pulls from the DLL itself so I don't have to maintain a copy in my solution. Its the answer to my 2nd attempt which I could never get working. After incorporating CustomResourceDictionary.cs from your provided example I ended up with this reference and I was done: <ResourceDictionary.MergedDictionaries> <custom:CustomResourceDictionary Location="Themes/Styles.Shared.xaml" TypeFromHostingAssembly="{x:Type ig:IgTheme}"/> </ResourceDictionary.MergedDictionaries>
That did the trick. Intellisense is happy, the project builds, and my modified ContentTemplate is happy using the IG colors and brushes.
Thank you!
Hi Kristopher,
One of the options you have is to use the ThemeManager framework to apply a certain theme. With it you simply have to execute the following line to apply a theme application wide:
Infragistics.Themes.ThemeManager.ApplicationTheme = new IgTheme();
The ThemeManager will track which IG controls are being used and will import their styles into the application resources.
If you need to import the resourse dictionaries manually you could check out the attached sample. In a nutshell I've created CustomResourceDictionary class tha iherits ResourceDictionary. This customeRD have two more props - Location and TypeFromHostingAssembly. The Location prop is expecting to geth the locatioon of the xaml file relative to the assembly it's contained in. TypeFromHostinAssembly is expecting a reference to type that is defined in the assembly containing the xaml styles. So the usage lookes like the following: