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://www.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

Parents
No Data
Reply
  • 28790
    Offline posted

    Hell Asle,

    I have been investigating into the behavior that you are referring to, and it appears that the issue with this is that the only colors that are specified are the ones that are used in the cell’s edit mode-related functionality. In order to have all of the colors specified, I believe you will need to include them with the file that the BuildLocationString is pointed to in this case.

    There are a couple of alternate recommendations that I can make on this matter as well. You mentioned that you do not want to write the styles in the Resources section of the grid, but have you considered putting these styles within a ResourceDictionary and then just merging that dictionary with your grids? This still requires some code to go into the XamDataGrid.Resources section, but it is about the same amount as setting your custom theme in this case.

    Another option is to simply include the relevant theme files and then merge them with the XamDataGrid.Resources section. These can be obtained from the C:\Program Files (x86)\Infragistics\<your version here>\WPF\DefaultStyles\DataPresenter directory, and the relevant files will be named DataPresenter<ThemeName>.xaml and DataPresenter<ThemeName>_Brushes.xaml. If you include these, make your modifications to them, and then merge them with the resources of your grid, this may be easier than tracking down all of the brushes that you would need.

    I hope this helps. Please let me know if you have any other questions or concerns on this matter.

Children