ThemedDataGrid Style names

Grids for WPF Forum

The latest build of this product (v25.1.4) was released 2 months ago, which was before this thread was created.
Posted 1 days ago by John Bell
Version: 25.1.4
Avatar

Hi,

Where can I find the ThemedDataGrid style names?

I need to tweak the style of the ThemedDataGrid.ColumnHeaderStyle. To do this I need to add the BasedOn attribute of the new Style element. If I don't use the BasedOn attribute it falls back to the WPF system themed style and I lose all the styling of the ThemedDataGrid.

I'm sure I will need this for other controls, so is there a list mapping the controls to their style names somewhere?

Thanks, John

[Modified 1 days ago]

Comments (7)

Answer - Posted 12 hours ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi John,

Our free DataGrid add-on is fully open source here on GitHub.  You can look at that file to see all the Styles and their keys.  The DataGrid style keys are on the DataGridResourceKeys class.

For native controls, we create Styles in a similar way with keys defined on SharedResourceKeys.

For our controls in various product assemblies, some Styles use predefined keys and some don't.  You'd have to look in the API reference for a related class like the SharedResourceKeys one above.  As an example, Bars has a BarsResourceKeys class.


Actipro Software Support

Posted 11 hours ago by John Bell
Avatar

Thanks for the information. The following code crashes, do you know why?

App.xaml.cs OnStartUp

ImageProvider.Default.ChromaticAdaptationMode = ImageChromaticAdaptationMode.DarkThemes;
ImageProvider.Default.UseMonochromeInHighContrast = true;

ThemeManager.BeginUpdate();
try
{
	ThemeManager.AreNativeThemesEnabled = true;
	ThemeManager.CurrentTheme = "Light";
}
finally
{
	ThemeManager.EndUpdate();
}

Window.xaml

<datagrid:ThemedDataGrid.ColumnHeaderStyle>
    <Style TargetType="{x:Type DataGridColumnHeader}" BasedOn="{StaticResource DataGridColumnHeaderStyleKey}" >
        <Setter Property="FontWeight" Value="Bold"/>
    </Style>
</datagrid:ThemedDataGrid.ColumnHeaderStyle>

Exception

System.Windows.Markup.XamlParseException
Inner Exception 1:
Exception: Cannot find resource named 'DataGridColumnHeaderStyleKey'. Resource names are case sensitive.

On further investigation, I beleive the problem is I'm not specifying the namespace for DataGridColumnHeaderStyleKey. But, I can't find the right one. I have:

xmlns:themes="http://schemas.actiprosoftware.com/winfx/xaml/themes"

The following BasedOn attribute compiles and works with intellisense, but fails at runtime with the above exception

BasedOn="{DynamicResource {x:Static themes:DataGridResourceKeys.DataGridColumnHeaderStyleKey}}"

[Modified 10 hours ago]

Posted 8 hours ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi John,

You are close.  If you change the last line to use StaticResource instead of DynamicResource, it will work.


Actipro Software Support

Posted 8 hours ago by John Bell
Avatar

So, that works for you. I wonder why it doesn't work for me? Same error. Using:

<Style TargetType="{x:Type DataGridColumnHeader}" BasedOn="{StaticResource themes:DataGridResourceKeys.DataGridColumnHeaderStyleKey}" >

I'm compiling to .NET8 with these packages, all version 25.1.0:

ActiproSoftware.Controls.WPF.DataGrid.Contrib

ActiproSoftware.Controls.WPF.Docking

ActiproSoftware.Controls.WPF.Editors

ActiproSoftware.Controls.WPF.Editors.Interop.DataGrid

ActiproSoftware.Controls.WPF.Editors.Ingterop.Grids

ActiproSoftware.Controls.WPF.Grids

ActiproSoftware.Controls.WPF.Shared

I'm not much of a xaml programmer, so my apologies, but it seems strange that it compiles but fails at runtime.

Posted 7 hours ago by Actipro Software Support - Cleveland, OH, USA
Avatar

I think this time you were missing the x:Static part.  It should be this:

BasedOn="{StaticResource {x:Static themes:DataGridResourceKeys.DataGridColumnHeaderStyleKey}}"


Actipro Software Support

Posted 7 hours ago by John Bell
Avatar

OMG, that's crazy, thanks for your patience, it works now.

Posted 7 hours ago by Actipro Software Support - Cleveland, OH, USA
Avatar

I know it does look daunting at first.  BasedOn's only work with StaticResource (not DynamicResource).  Then the x:Static part means look at a static property of that type/prop name to get the actual key.  Hope that helps clarify.


Actipro Software Support

Add Comment

Please log in to a validated account to post comments.