Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
220
Styling XamDataGrid by extending an existing control theme
posted

Hi, I want to use one of your themes (RoyalDark) in my solution, but I want to do some minor modification to the theme, such as colors.

I've tried the Resource Washer, but that adds color to way too many elements and does not look good.

I've tried using Theme="RoyalDark" and customize the style locally in the XamDataGrid.Resources, but it's not a suitable way because there will be a lot of code duplication since I have many datagrids in my solution.

I've also tried adding the RoyalDark-resources from the theme folder to my solution and the App.xaml and then editing the colors in the resource files (i.e. DataPresenterRoyalDark_Brushes.xaml). This works, but it seems exaggerated when I just want to make small changes to the theme. It is also harder to keep track of my customizations to the original theme.

I found a example in your documentation, 'Extending an Existing Control Theme', which sounds like exactly what I'm looking for.
https://es.infragistics.com/help/wpf/thememanager-extending-existing-control-theme

The example shows how to do it with XamTileManager, but I'm trying to get this technique working for XamDataGrid, since I have a lot of those in my solution.
Following the example, I based my custom theme on the RoyalDark theme:

public class RoyalExtendedTheme : RoyalDarkTheme

And then override the mapping of XamDataGrid with a XAML resource-file I created:

Mappings[ControlMappingKeys.XamDataGrid] = ThemeBase.BuildLocationString(assemblyFullName, @"/Themes/RoyalExtendedTheme.Colors.xaml");

The XAML resource-file just consist of three colors, which targets the "accent" colors of the theme, identified in the theme resources "DataPresenterRoyalDark_Brushes.xaml" and "Theme.Colors.xaml":

<Color x:Key="Color_011">#FF00b6f1</Color>  <!--BG SELECTED/PRESSED/CHECKED-->  
<Color x:Key="Color_013">#FF00b6f1</Color>  <!--BrD FOCUS-->  
<Color x:Key="Color_0013">#FF00b6f1</Color>  <!--Hyperlinks Normal-->

The theme is then applied to a XamDataGrid:

<igDataPresenter:XamDataGrid BindToSampleData="True">
	<ig:ThemeManager.Theme>
		<themes:RoyalExtendedTheme />
	</ig:ThemeManager.Theme>
</igDataPresenter:XamDataGrid>

This do not work, no sign of the modified colors and the style of the XamDataGrid seems to mostly be the generic theme. Please see screenshot below.

Removing the colors from the XAML resource-file and making it empty produces the same result. So I'm guessing it has to be something with the XamDataGrid mapping override.

So the question is: How do you override the XamDataGrid mapping in order to make this work?
Since XamDataGrid is of the DataPresenter family, should my extended theme be based on Infragistics.Windows.Themes.DataPresenterRoyalDark? If so, how - it's a DataPresenterResourceSet and not a BuiltInThemeBase?
Must the XAML resource-file contain all of the DataPresenterRoyalDark-resources not just part's of it?

Please see my attached sample-solution.

6204.ExtendTheme.zip