telerik / UI-For-UWP

This repo contains the source code for Telerik UI for Universal Windows Platform (UWP), which includes 20+ UI controls for developers building UWP applications.
http://www.telerik.com/uwp/
Other
1.16k stars 234 forks source link

DataGridColumnHeader layout issue #504

Closed RobbyRobbyRobby closed 2 years ago

RobbyRobbyRobby commented 2 years ago

Content Layout of header in the column header ignores properties.

Steps to Reproduce

  1. Add a RadGrid
  2. Disable automatic columns
  3. Add a TemplateColumn (Issue may be present for other types)
  4. Add a Column Header definition to the TemplateColumn.
  5. Add a Button (for example) to column header, and attempt to change alignment. You will be ignored.

Expected Behavior

Alignment, Padding, Margin, ContentAlignment should be respected.

Actual Behavior

Alignment, Padding, Content Alignment are not effective.

Basic Information

Screenshots

image

Code Example

I have coloured the different framework elements to better show what has, and what has not, worked. The output is as in image preceding.

<UserControl.Resources>
     <Style x:Key="customHeaderStyle" TargetType="localPrimitives:DataGridColumnHeader">
         <Setter Property="Padding" Value="0" />
         <Setter Property="Margin" Value="0" />
         <Setter Property="Background" Value="Green" />
         <Setter Property="HorizontalAlignment" Value="Stretch" />
         <Setter Property="HorizontalContentAlignment" Value="Stretch" />
     </Style>
</UserControl.Resources>

                <telerikGrid:DataGridTemplateColumn
                    x:Name="selectColumn"
                    Width="44"
                    CanUserResize="False"
                    HeaderStyle="{StaticResource customHeaderStyle}"
                    SizeMode="Fixed">
                    <telerikGrid:DataGridTemplateColumn.Header>
                        <Grid
                            Margin="0"
                            Padding="0"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch"
                            Background="Yellow">
                            <Button
                                x:Name="checkAllButton"
                                Margin="0"
                                Padding="0"
                                HorizontalAlignment="Stretch"
                                VerticalAlignment="Stretch"
                                HorizontalContentAlignment="Center"
                                VerticalContentAlignment="Center"
                                BorderBrush="Red"
                                BorderThickness="1"
                                Click="checkAllButton_Click"
                                Content=""
                                FontFamily="Segoe MDL2 Assets"
                                Style="{ThemeResource ButtonRevealStyle}" />
                        </Grid>
                    </telerikGrid:DataGridTemplateColumn.Header>

Further Notes

I have tried customizing the underlying theme resources in the DataGrid, but have had no luck. I suspect there is a StackPannel or similar in the header fouling it up.

LanceMcCarthy commented 2 years ago

Hi Rob,

As I mentioned in my Twitter reply, this is expected because of the header's ControlTemplate layout. as you suspected, there is a StackPanel involved. This is easy to override to get the results you want.

Here's the default Style and ControlTemplate for the DataGridColumnHeader. If you update your Style to include the ControlTemplate, you can modify it to suit your needs.

Here's a screenshot to help clarify exactly where your custom header content gets rendered:

image

Important : Be careful not to remove anything that has a PART_ prefix. You can set the undesired part's Visibility="Collapsed". If a PART is missing, you'll get a NRE because it is referenced in the control's code.

Example

To give you a head start, here's your Style, but I added the ControlTemplate to it. You can use this as a starting point (and a fresh start in case you need to start over 😁).

<Style x:Key="customHeaderStyle" TargetType="localPrimitives:DataGridColumnHeader">
     <Setter Property="Padding" Value="0" />
     <Setter Property="Margin" Value="0" />
     <Setter Property="Background" Value="Green" />
     <Setter Property="HorizontalAlignment" Value="Stretch" />
     <Setter Property="HorizontalContentAlignment" Value="Stretch" />
     <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="localPrimitives:DataGridColumnHeader">
                <Grid x:Name="rootPanel" Background="{TemplateBinding Background}" HorizontalAlignment="Stretch">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal" />
                            <VisualState x:Name="Filtered">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FilteredHighlight" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="SelectedStates">
                            <VisualState x:Name="Unselected" />
                            <VisualState x:Name="Selected">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="headerContent" Storyboard.TargetProperty="Foreground">
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{ThemeResource TelerikGridServiceColumnActiveForegroundBrush}"/>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="rootPanel" Storyboard.TargetProperty="Background">
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{ThemeResource TelerikGridServiceColumnActiveBackgroundBrush}"/>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ResizeHandle" Storyboard.TargetProperty="Foreground">
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{ThemeResource TelerikGridServiceColumnActiveForegroundBrush}"/>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Grid Padding="{TemplateBinding Padding}"  HorizontalAlignment="Stretch">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <StackPanel Orientation="Horizontal" 
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                            <ContentPresenter x:Name="headerContent" Content="{TemplateBinding Content}" Margin="8"/>
                            <TextBlock Text="{Binding SortDirection, Converter={StaticResource SortDirectionConverter}}"
                                   FontFamily="{ThemeResource SymbolThemeFontFamily}" FontSize="10"  Margin="2,0,4,2" VerticalAlignment="Center"/>
                        </StackPanel>
                        <primitivesCommon:InlineButton Style="{StaticResource GridServiceButtonStyle}"  x:Name="PART_FilterButton" HorizontalAlignment="Right" VerticalAlignment="Stretch"   
                                                           Grid.Column="1" Padding="8,0,8,4" VerticalContentAlignment="Center"
                                                           Background="Transparent" PointerOverBackgroundBrush="Transparent" PressedBackgroundBrush="Transparent" 
                                                           PointerOverForegroundBrush="{ThemeResource TelerikGridHeaderPointerOverForegroundBrush}"
                                                           Foreground="{TemplateBinding Foreground}" PressedForegroundBrush="{TemplateBinding Foreground}"
                                                           Visibility="{TemplateBinding FilterGlyphVisibility}">
                            <primitivesCommon:InlineButton.Content>
                                <TextBlock Text="&#xe71c;" FontFamily="{ThemeResource SymbolThemeFontFamily}" FontSize="12"
                                           HorizontalAlignment="Center" VerticalAlignment="Center"/>
                            </primitivesCommon:InlineButton.Content>
                        </primitivesCommon:InlineButton>
                        <Thumb x:Name="PART_ResizeHandle" Style="{StaticResource ColumnHeaderResizeThumb}" Background="Transparent" Grid.Column="2" Visibility="{TemplateBinding ResizeHandleVisiblity}">
                        </Thumb>
                    </Grid>
                    <Rectangle x:Name="FilteredHighlight" Height="2" Fill="{ThemeResource TelerikGridServiceButtonBackgroundBrush}" 
                               VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Margin="0,0,0,4" Visibility="Collapsed" Grid.ColumnSpan="3"/>
                    <Rectangle Fill="{ThemeResource TelerikGridInnerShadowBrush}" Height="1" VerticalAlignment="Bottom" Margin="0,1,0,3" Grid.ColumnSpan="3"/>
                    <Rectangle Fill="{ThemeResource TelerikGridShadowBrush}" Height="3" VerticalAlignment="Bottom" Margin="0,3,0,0" Grid.ColumnSpan="3"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Edited to improve spelling, explanation and add example.

RobbyRobbyRobby commented 2 years ago

That's fantastic, thanks Lance!

RobbyRobbyRobby commented 2 years ago

Hi again @LanceMcCarthy

I've tried this but can't seem to escape an error;

As soon as I add the style (HeaderStyle="{StaticResource customHeaderStyle}" to my teemplatecolumn, I get this:

System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component. at Windows.UI.Xaml.UIElement.Measure(Size availableSize) at Telerik.UI.Xaml.Controls.Grid.DataGridColumn.MeasureCellContainer(Double availableWidth, UIElement container) at Telerik.UI.Xaml.Controls.Grid.DataGridColumn.MeasureCell(GridCellModel cell, Double availableWidth) at Telerik.UI.Xaml.Controls.Grid.RadDataGrid.MeasureHeaderCell(GridHeaderCellModel cell) at Telerik.UI.

I've attempted with earlier versions of Telerik.UI and WinUI without success. I also removed everything from my column and header templates in case that was the issue but it persists.

Does the above code work for you?

I'm going to go try to research the error If I find anything I'll mention it here.

LanceMcCarthy commented 2 years ago

[update] I can reproduce this. This type of exception usually occurs when there's a problem with the Measure & Arrange pass of the elements.

I'll investigate it this morning and let you know the outcome.

LanceMcCarthy commented 2 years ago

Update 2: Fixed it! confirmed working at runtime:

image

the problem was that the Style & ControlTemplate was missing some critical parts. This is my fault for only copying the Style out of the ResourceDictionary... instead of using the Blend (or VS) trick of:

Document Outline > right click on a DataGridColumnHeader object instance > Edit Style > Edit a copy

Here's my entire working example's MainPage, which has the resources:

<Page x:Name="ThisPage"
      x:Class="CstmColumnHeaderCtrlTemplate.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="using:CstmColumnHeaderCtrlTemplate"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:tkGrid="using:Telerik.UI.Xaml.Controls.Grid"
      xmlns:models="using:CommonHelpers.Models"
      xmlns:common="using:Telerik.UI.Xaml.Controls.Primitives.Common"
      xmlns:primitives="using:Telerik.UI.Xaml.Controls.Grid.Primitives"
      mc:Ignorable="d"
      Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
      xmlns:localView="using:Telerik.UI.Xaml.Controls.Grid.View">

    <Page.Resources>
        <ControlTemplate x:Key="InlineButtonControlTemplate"
                         TargetType="common:InlineButton">
            <Grid>
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal" />
                        <VisualState x:Name="PointerOver">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                                               Storyboard.TargetProperty="Background">
                                    <DiscreteObjectKeyFrame KeyTime="0"
                                                            Value="{Binding PointerOverBackgroundBrush, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                                               Storyboard.TargetProperty="BorderBrush">
                                    <DiscreteObjectKeyFrame KeyTime="0"
                                                            Value="{Binding PointerOverBorderBrush, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                               Storyboard.TargetProperty="Foreground">
                                    <DiscreteObjectKeyFrame KeyTime="0"
                                                            Value="{Binding PointerOverForegroundBrush, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Icon"
                                                               Storyboard.TargetProperty="Source">
                                    <DiscreteObjectKeyFrame KeyTime="0"
                                                            Value="{Binding PointerOverIconSource, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Pressed">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                                               Storyboard.TargetProperty="Background">
                                    <DiscreteObjectKeyFrame KeyTime="0"
                                                            Value="{Binding PressedBackgroundBrush, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                                               Storyboard.TargetProperty="BorderBrush">
                                    <DiscreteObjectKeyFrame KeyTime="0"
                                                            Value="{Binding PressedBorderBrush, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                               Storyboard.TargetProperty="Foreground">
                                    <DiscreteObjectKeyFrame KeyTime="0"
                                                            Value="{Binding PressedForegroundBrush, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Icon"
                                                               Storyboard.TargetProperty="Source">
                                    <DiscreteObjectKeyFrame KeyTime="0"
                                                            Value="{Binding PressedIconSource, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Disabled">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                                               Storyboard.TargetProperty="Background">
                                    <DiscreteObjectKeyFrame KeyTime="0"
                                                            Value="{Binding DisabledBackgroundBrush, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                                               Storyboard.TargetProperty="BorderBrush">
                                    <DiscreteObjectKeyFrame KeyTime="0"
                                                            Value="{Binding DisabledBorderBrush, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                               Storyboard.TargetProperty="Foreground">
                                    <DiscreteObjectKeyFrame KeyTime="0"
                                                            Value="{Binding DisabledForegroundBrush, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Icon"
                                                               Storyboard.TargetProperty="Source">
                                    <DiscreteObjectKeyFrame KeyTime="0"
                                                            Value="{Binding DisabledIconSource, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
                <Border x:Name="Border"
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                    <Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                          Margin="{TemplateBinding Padding}"
                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Image x:Name="Icon"
                               Source="{TemplateBinding IconSource}"
                               Style="{TemplateBinding IconStyle}" />
                        <ContentPresenter x:Name="ContentPresenter"
                                          ContentTemplate="{TemplateBinding ContentTemplate}"
                                          Grid.Column="1"
                                          Content="{TemplateBinding Content}"
                                          Foreground="{TemplateBinding Foreground}"
                                          FontStyle="{TemplateBinding FontStyle}"
                                          FontFamily="{TemplateBinding FontFamily}"
                                          FontWeight="{TemplateBinding FontWeight}"
                                          FontSize="{TemplateBinding FontSize}" />
                    </Grid>
                </Border>
            </Grid>
        </ControlTemplate>
        <Color x:Key="TelerikSelectedColor">#FF006AC1</Color>
        <Color x:Key="TelerikHighlightedColor">#FF2086D9</Color>
        <Color x:Key="TelerikPressedBackgroundColor">#FF000000</Color>
        <Color x:Key="TelerikPressedForegroundColor">#FFFFFFFF</Color>
        <Color x:Key="TelerikWhiteColor">#FFFFFFFF</Color>
        <SolidColorBrush x:Key="TelerikGridHeaderBackgroundBrush"
                         Color="#FFC6C6C6" />
        <SolidColorBrush x:Key="TelerikGridHeaderForegroundBrush"
                         Color="#CC000000" />
        <SolidColorBrush x:Key="TelerikGridHeaderPointerOverForegroundBrush"
                         Color="#FF000000" />
        <SolidColorBrush x:Key="TelerikGridShadowBrush"
                         Color="#4C838282" />
        <SolidColorBrush x:Key="TelerikGridInnerShadowBrush"
                         Color="#26000000" />
        <SolidColorBrush x:Key="TelerikGridServiceColumnActiveForegroundBrush"
                         Color="{ThemeResource TelerikWhiteColor}" />
        <SolidColorBrush x:Key="TelerikGridServiceColumnActiveBackgroundBrush"
                         Color="{ThemeResource TelerikSelectedColor}" />
        <SolidColorBrush x:Key="TelerikGridServiceButtonBackgroundBrush"
                         Color="{ThemeResource TelerikSelectedColor}" />
        <SolidColorBrush x:Key="TelerikGridServiceButtonForegroundBrush"
                         Color="{ThemeResource TelerikWhiteColor}" />
        <SolidColorBrush x:Key="TelerikGridServiceButtonPointerOverBackgroundBrush"
                         Color="{ThemeResource TelerikHighlightedColor}" />
        <SolidColorBrush x:Key="TelerikGridServiceButtonPressedBackgroundBrush"
                         Color="{ThemeResource TelerikPressedBackgroundColor}" />
        <SolidColorBrush x:Key="TelerikGridServiceButtonPressedForegroundBrush"
                         Color="{ThemeResource TelerikPressedForegroundColor}" />
        <Style x:Key="GridServiceButtonStyle"
               TargetType="common:InlineButton">
            <Setter Property="AutomationProperties.Name"
                    Value="Filter" />
            <Setter Property="Background"
                    Value="{ThemeResource TelerikGridServiceButtonBackgroundBrush}" />
            <Setter Property="Foreground"
                    Value="{ThemeResource TelerikGridServiceButtonForegroundBrush}" />
            <Setter Property="PointerOverBackgroundBrush"
                    Value="{ThemeResource TelerikGridServiceButtonPointerOverBackgroundBrush}" />
            <Setter Property="PointerOverForegroundBrush"
                    Value="{ThemeResource TelerikGridServiceButtonForegroundBrush}" />
            <Setter Property="PressedBackgroundBrush"
                    Value="{ThemeResource TelerikGridServiceButtonPressedBackgroundBrush}" />
            <Setter Property="PressedForegroundBrush"
                    Value="{ThemeResource TelerikGridServiceButtonPressedForegroundBrush}" />
            <Setter Property="HorizontalAlignment"
                    Value="Left" />
            <Setter Property="VerticalAlignment"
                    Value="Center" />
            <Setter Property="HorizontalContentAlignment"
                    Value="Center" />
            <Setter Property="VerticalContentAlignment"
                    Value="Center" />
            <Setter Property="Padding"
                    Value="0" />
            <Setter Property="Template"
                    Value="{StaticResource InlineButtonControlTemplate}" />
        </Style>
        <localView:SortDirectionToGlyphConverter x:Key="SortDirectionConverter" />
        <Style x:Key="ColumnHeaderResizeThumb"
               TargetType="Thumb">
            <Setter Property="Background"
                    Value="Transparent" />
            <Setter Property="BorderThickness"
                    Value="0" />
            <Setter Property="IsTabStop"
                    Value="False" />
            <Setter Property="BorderBrush"
                    Value="{ThemeResource ThumbBorderThemeBrush}" />
            <Setter Property="FontSize"
                    Value="16" />
            <Setter Property="Margin"
                    Value="2" />
            <Setter Property="Padding"
                    Value="0" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Thumb">
                        <Border Background="{TemplateBinding Background}"
                                Padding="{TemplateBinding Padding}">
                            <TextBlock FontFamily="Segoe MDL2 Assets"
                                       FontSize="{TemplateBinding FontSize}"
                                       HorizontalAlignment="Center"
                                       IsHitTestVisible="False"
                                       Text="&#xE784;"
                                       VerticalAlignment="Center" />
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="CustomColumnHeaderStyle"
               TargetType="primitives:DataGridColumnHeader">
            <Setter Property="Foreground"
                    Value="{ThemeResource TelerikGridHeaderForegroundBrush}" />
            <Setter Property="Background"
                    Value="{ThemeResource TelerikGridHeaderBackgroundBrush}" />
            <Setter Property="HorizontalContentAlignment"
                    Value="Left" />
            <Setter Property="VerticalContentAlignment"
                    Value="Center" />
            <Setter Property="MinWidth"
                    Value="6" />
            <Setter Property="MinHeight"
                    Value="6" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="primitives:DataGridColumnHeader">
                        <Grid x:Name="rootPanel"
                              Background="{TemplateBinding Background}"
                              HorizontalAlignment="Stretch">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal" />
                                    <VisualState x:Name="Filtered">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FilteredHighlight"
                                                                           Storyboard.TargetProperty="Visibility">
                                                <DiscreteObjectKeyFrame KeyTime="0:0:0"
                                                                        Value="Visible" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="SelectedStates">
                                    <VisualState x:Name="Unselected" />
                                    <VisualState x:Name="Selected">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="headerContent"
                                                                           Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0:0:0"
                                                                        Value="{ThemeResource TelerikGridServiceColumnActiveForegroundBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="rootPanel"
                                                                           Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0:0:0"
                                                                        Value="{ThemeResource TelerikGridServiceColumnActiveBackgroundBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ResizeHandle"
                                                                           Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0:0:0"
                                                                        Value="{ThemeResource TelerikGridServiceColumnActiveForegroundBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Grid HorizontalAlignment="Stretch"
                                  Padding="{TemplateBinding Padding}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <StackPanel HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                            Orientation="Horizontal"
                                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                    <ContentPresenter x:Name="headerContent"
                                                      Content="{TemplateBinding Content}"
                                                      Margin="8" />
                                    <TextBlock FontFamily="{ThemeResource SymbolThemeFontFamily}"
                                               FontSize="10"
                                               Margin="2,0,4,2"
                                               Text="{Binding SortDirection, Converter={StaticResource SortDirectionConverter}}"
                                               VerticalAlignment="Center" />
                                </StackPanel>
                                <common:InlineButton x:Name="PART_FilterButton"
                                                     Background="Transparent"
                                                     Grid.Column="1"
                                                     Foreground="{TemplateBinding Foreground}"
                                                     HorizontalAlignment="Right"
                                                     Padding="8,0,8,4"
                                                     PointerOverBackgroundBrush="Transparent"
                                                     PressedForegroundBrush="{TemplateBinding Foreground}"
                                                     PointerOverForegroundBrush="{ThemeResource TelerikGridHeaderPointerOverForegroundBrush}"
                                                     PressedBackgroundBrush="Transparent"
                                                     Style="{StaticResource GridServiceButtonStyle}"
                                                     VerticalContentAlignment="Center"
                                                     VerticalAlignment="Stretch"
                                                     Visibility="{TemplateBinding FilterGlyphVisibility}">
                                    <TextBlock FontFamily="{ThemeResource SymbolThemeFontFamily}"
                                               FontSize="12"
                                               HorizontalAlignment="Center"
                                               Text="&#xE71C;"
                                               VerticalAlignment="Center" />
                                </common:InlineButton>
                                <Thumb x:Name="PART_ResizeHandle"
                                       Background="Transparent"
                                       Grid.Column="2"
                                       Style="{StaticResource ColumnHeaderResizeThumb}"
                                       Visibility="{TemplateBinding ResizeHandleVisiblity}" />
                            </Grid>
                            <Rectangle x:Name="FilteredHighlight"
                                       Grid.ColumnSpan="3"
                                       Fill="{ThemeResource TelerikGridServiceButtonBackgroundBrush}"
                                       HorizontalAlignment="Stretch"
                                       Height="2"
                                       Margin="0,0,0,4"
                                       VerticalAlignment="Bottom"
                                       Visibility="Collapsed" />
                            <Rectangle Grid.ColumnSpan="3"
                                       Fill="{ThemeResource TelerikGridInnerShadowBrush}"
                                       Height="1"
                                       Margin="0,1,0,3"
                                       VerticalAlignment="Bottom" />
                            <Rectangle Grid.ColumnSpan="3"
                                       Fill="{ThemeResource TelerikGridShadowBrush}"
                                       Height="3"
                                       Margin="0,3,0,0"
                                       VerticalAlignment="Bottom" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Page.Resources>

    <Page.DataContext>
        <local:MainViewModel x:Name="ViewModel" />
    </Page.DataContext>

    <Grid>
        <tkGrid:RadDataGrid ItemsSource="{Binding Employees}"
                            AutoGenerateColumns="False">
            <tkGrid:RadDataGrid.Columns>
                <tkGrid:DataGridTextColumn Header="Position"
                                           PropertyName="Position"
                                           SizeMode="Auto" />

                <tkGrid:DataGridTemplateColumn Header="Name"
                                               SizeMode="Stretch"
                                               HeaderStyle="{StaticResource CustomColumnHeaderStyle}">
                    <tkGrid:DataGridTemplateColumn.CellContentTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Text="I am a TemplateColumn" />
                            </StackPanel>
                        </DataTemplate>
                    </tkGrid:DataGridTemplateColumn.CellContentTemplate>
                </tkGrid:DataGridTemplateColumn>
            </tkGrid:RadDataGrid.Columns>
        </tkGrid:RadDataGrid>
    </Grid>
</Page>
RobbyRobbyRobby commented 2 years ago

Legendary @LanceMcCarthy !

I spent the rest the day hacking it down to less and less trying to make it succeed, without any real progress. So I am sooo thankful for the help.

I'll implement it and try today.

Rob. Valley Software.

RobbyRobbyRobby commented 2 years ago

It works!

Only 'gotcha' to be aware of is that the filter/order buttons will appear on top of your content; you can

a) change this Z order or b) disable the buttons.

In my case, I was already disabling and hiding them.

Thanks again. Rob.

image