ThemeDatagrid does not display re-templated SelectAllButtonTemplate

Grids for WPF Forum

Posted 4 years ago by Procam
Version: 19.1.0686
Platform: .NET 3.0 (Core)
Environment: Windows 10 (64-bit)
Avatar

Hello,

I created an attached property for Datagrid in order to re-template the SelectAllButton.

In the code when I use standard <Datagrid ../> it works, but when changed to

<datagrid:ThemedDataGrid

the re-templated SelectAllButton is not displayed, but the default.

How can I send you a zipped sample solution?

Comments (5)

Posted 4 years ago by Procam
Avatar

Neither using the direct way with re-styling it is not working. I paste here the whole code for that. In the code below the 1st datagrid works and the 2nd not:

<Window x:Class="WpfApp3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:datagrid="http://schemas.actiprosoftware.com/winfx/xaml/datagrid"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <Style x:Key="{ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}"
       TargetType="{x:Type Button}">
            <Setter Property="Width" Value="60"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <DockPanel HorizontalAlignment="Center"
                           IsHitTestVisible="False"
                           VerticalAlignment="Center">
                            <TextBlock FontSize="18"
                               FontWeight="ExtraBlack"
                               Text="A"
                               TextAlignment="Center"
                               ToolTip="DataGridHowTo" />
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <StackPanel Orientation="Vertical">
        <DataGrid AutoGenerateColumns="True" RowHeaderWidth="60" Height="100"
                           ItemsSource="{Binding Customers, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" />
        <datagrid:ThemedDataGrid AutoGenerateColumns="True" RowHeaderWidth="60" Height="100"
                           ItemsSource="{Binding Customers, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" />
 
    </StackPanel>
</Window>

Is it a lack of ThemeDatagrid?

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

It looks like our current DataGrid references a Style defined in our XAML for that button and isn't referencing that key.  We tried renaming the key to the ComponentResource you posted but ran into some issues with it getting picked up.  We added a new key for the 2020.1 version (not out yet) that you can override with this kind of code in your App.Resources:

<Style x:Key="{x:Static themes:DataGridResourceKeys.DataGridSelectAllButtonStyleKey}" TargetType="{x:Type Button}">

If you want to update this in a current version, you'd have to grab our DataGrid.Contrib source off of Codeplex and alter that.  ThemedDataGrid's full source is in that repo.


Actipro Software Support

Posted 4 years ago by Procam
Avatar

How do you mean to alter that?

I copied to my solution the ThemeDataGrid class with no modification (namespace stayed untouched). Also copied the DataGridResourcesKeys (namespace stayed untouched), where I added:

public static ResourceKey DataGridSelectAllButtonStyleKey
{
	get
	{
		if (dataGridSelectAllButtonStyleKey == null)
			dataGridSelectAllButtonStyleKey = new ComponentResourceKey(typeof(DataGridResourceKeys), "DataGridSelectAllButtonStyleKey");
		return dataGridSelectAllButtonStyleKey;
	}
}

Then the style in my resources looks like:

<Style x:Key="{x:Static themes2:DataGridResourceKeys.DataGridSelectAllButtonStyleKey}" TargetType="{x:Type Button}">
            <Setter Property="Width" Value="60"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <DockPanel HorizontalAlignment="Center"
                   IsHitTestVisible="False"
                   VerticalAlignment="Center">
                            <TextBlock FontSize="18"
                       FontWeight="ExtraBlack"
                       Text="A"
                       TextAlignment="Center"
                       ToolTip="DataGridHowTo" />
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

Using the local ThemeDataGrid and when I run my sample app, no datagrid is displayed.

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

If you only copied the classes, then you'd also have to clone the XAML and treat it as a new custom control.  My guess is that it's not showing because it can't find any Style/Template for the ThemedDataGrid class you copied.


Actipro Software Support

Posted 4 years ago by Procam
Avatar

Ok, you mean the DataGrid.xaml? It involves to copy also another classes: FocusBehaviour, DataGridCursor, etc. Too many changes for such apparently trivial SelectAllButton. We will wait to new uncomming version, as you stated above.

[Modified 4 years ago]

The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.