Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3340584
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:37:28+00:00 2026-05-18T00:37:28+00:00

Thanks for reading my question! I have a problem with customizing a DataGrid RowGroupHeader,

  • 0

Thanks for reading my question!
I have a problem with customizing a DataGrid RowGroupHeader, the situation is:
I need a way of taking control over a DataGrid RowGroupHeader as I want to display some databound values in it. The values will be generated at runtime so the RowGroupHeaderStyle needs to be generated and added to DataGrid’s RowGroupHeaderStyles property at runtime too (possibly using XamlReader.Load).
Additionally the position of the databound value within the RowGroupHeader should be aligned with a corresponding column from the DataGrid.
I’ve managed to create a working template using this post MS Forum but I had no luck with positioning the databound element, in my case TextBlock, to correctly align with a given DataGrid column.
Any suggestions?
Many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:37:29+00:00Added an answer on May 18, 2026 at 12:37 am

    This hasn’t been an easy one but after some extensive googling and piecing up other people’s experiences I’ve come up with this that work fine for me

    string loadString = @"<Style xmlns=""http://schemas.microsoft.com/client/2007"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" 
                                                     xmlns:localprimitives=""clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data""
    xmlns:vsm=""clr-namespace:System.Windows;assembly=System.Windows""
    xmlns:data=""clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"" TargetType=""data:DataGridRowGroupHeader"">
                    <Setter Property=""Cursor"" Value=""Arrow"" />
                    <Setter Property=""IsTabStop"" Value=""False"" />
                    <Setter Property=""Background"" Value=""#FFE4E8EA"" />
                    <Setter Property=""Height"" Value=""20""/>              
                    <Setter Property=""Template"">
                        <Setter.Value>
                            <ControlTemplate TargetType=""data:DataGridRowGroupHeader"">
                                <localprimitives:DataGridFrozenGrid Name=""Root"" Background=""{TemplateBinding Background}"">
                                    <vsm:VisualStateManager.VisualStateGroups>
                                        <vsm:VisualStateGroup x:Name=""CurrentStates"">
                                            <vsm:VisualState x:Name=""Regular""/>
                                            <vsm:VisualState x:Name=""Current"">
                                                <Storyboard>
                                                    <DoubleAnimation Storyboard.TargetName=""FocusVisual"" Storyboard.TargetProperty=""Opacity"" To=""1"" Duration=""0"" />
                                                </Storyboard>
                                            </vsm:VisualState>
                                        </vsm:VisualStateGroup>
                                    </vsm:VisualStateManager.VisualStateGroups>
                                    <localprimitives:DataGridFrozenGrid.Resources>
    
                                    </localprimitives:DataGridFrozenGrid.Resources>
    
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width=""Auto"" />
                                        <ColumnDefinition Width=""Auto"" />
                                        <ColumnDefinition Width=""Auto"" />
                                        <ColumnDefinition Width=""Auto"" />
                                        <ColumnDefinition Width=""Auto"" />
                                        <ColumnDefinition Width=""Auto"" />"     
    

    At this point I have some dynamic columns in the grid so I’m adding them just as the Grid.ColumnDefinitions so far but if your datagrid is static then you put the right number of columns.

    + colStr1 +
                                   @"</Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height=""Auto""/>
                                        <RowDefinition/>
                                        <RowDefinition Height=""Auto""/>
                                    </Grid.RowDefinitions>
                                    <StackPanel x:Name=""CustomRGHStackPanel"" Orientation=""Horizontal"" Tag=" + _tagNo + @"  Grid.Column=""3"" Grid.Row=""1""  VerticalAlignment=""Center"" Margin=""0,1,0,1"">
                                        <StackPanel.Resources>
                                            <Style  TargetType=""data:DataGridCell"">
                                                <Setter Property=""Background"" Value=""Transparent"" />
                                                <Setter Property=""HorizontalContentAlignment"" Value=""Stretch"" />
                                                <Setter Property=""VerticalContentAlignment"" Value=""Stretch"" />
                                                <Setter Property=""IsTabStop"" Value=""False"" />
                                                <Setter Property=""FontWeight"" Value=""Black""/>
                                                <Setter Property=""Template"">
                                                    <Setter.Value>
                                                        <ControlTemplate TargetType=""data:DataGridCell"">
                                                            <Grid Margin=""1,-1,-1,0"" >
                                                                <Grid Name=""Root"" Background=""{TemplateBinding Background}"" Margin=""5,0,0,0"">
                                                                    <vsm:VisualStateManager.VisualStateGroups>
                                                                        <vsm:VisualStateGroup x:Name=""CurrentStates"">
                                                                            <vsm:VisualState x:Name=""Regular"" />
                                                                            <vsm:VisualState x:Name=""Current"">
                                                                                <Storyboard>
                                                                                    <DoubleAnimation Storyboard.TargetName=""FocusVisual"" Storyboard.TargetProperty=""Opacity"" To=""1"" Duration=""0"" />
                                                                                </Storyboard>
                                                                            </vsm:VisualState>
                                                                        </vsm:VisualStateGroup>
                                                                        <vsm:VisualStateGroup x:Name=""ValidationStates"">
                                                                            <vsm:VisualState x:Name=""Valid""/>
                                                                            <vsm:VisualState x:Name=""Invalid"">
                                                                                <Storyboard>
                                                                                    <DoubleAnimation Storyboard.TargetName=""InvalidVisualElement"" Storyboard.TargetProperty=""Opacity"" Duration=""0"" To=""1""/>
                                                                                    <ColorAnimation Storyboard.TargetName=""FocusVisual"" Storyboard.TargetProperty=""(Fill).Color"" Duration=""0"" To=""#FFFFFFFF""/>
                                                                                </Storyboard>
                                                                            </vsm:VisualState>
                                                                        </vsm:VisualStateGroup>
                                                                    </vsm:VisualStateManager.VisualStateGroups>
    
                                                                    <Grid.ColumnDefinitions>
                                                                        <ColumnDefinition />
                                                                        <ColumnDefinition Width=""Auto"" />
                                                                    </Grid.ColumnDefinitions>
    
                                                                    <Rectangle Name=""FocusVisual"" Stroke=""#FF6DBDD1"" StrokeThickness=""1"" Fill=""#66FFFFFF"" HorizontalAlignment=""Stretch"" 
                               VerticalAlignment=""Stretch"" IsHitTestVisible=""false"" Opacity=""0"" />
    
                                                                    <ContentPresenter
                        Content=""{TemplateBinding Content}""
                        ContentTemplate=""{TemplateBinding ContentTemplate}""
                        HorizontalAlignment=""{TemplateBinding HorizontalContentAlignment}""
                        VerticalAlignment=""{TemplateBinding VerticalContentAlignment}""
                        Margin=""{TemplateBinding Padding}"" />
    
                                                                    <Rectangle x:Name=""InvalidVisualElement"" IsHitTestVisible=""False"" StrokeThickness=""1"" Stroke=""#FFDC000C"" HorizontalAlignment=""Stretch"" VerticalAlignment=""Stretch"" Opacity=""0""/>
                                                                    <Rectangle Name=""q1q"" Fill=""#c9caca"" Grid.Column=""1"" Margin=""1,0,1,0"" HorizontalAlignment=""Right"" VerticalAlignment=""Stretch"" Width=""0"" />
    
                                                                </Grid>
                                                                <Rectangle Name=""qq"" Fill=""#c9caca""  Margin=""1,0,1,0"" HorizontalAlignment=""Left"" VerticalAlignment=""Stretch"" Width=""1"" />
    
                                                            </Grid>
                                                        </ControlTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                            </Style>
                                        </StackPanel.Resources>
                                        <data:DataGridCell  Content=""{Binding Name}""/>
                                        <data:DataGridCell  Content=""""/>
                                        <data:DataGridCell  Content=""""/>
                                        <data:DataGridCell  Content=""""/>
                                        <data:DataGridCell  Content=""""/>
                                        <data:DataGridCell HorizontalContentAlignment=""Left"" Margin=""7,0,0,0"" Content=""{Binding Converter={StaticResource myConverter}, ConverterParameter=TotalScore}""/>" + colStr2 +
                                    @"</StackPanel>
                                    <Rectangle Grid.Column=""1"" Grid.ColumnSpan=""5"" Fill=""#FFFFFFFF"" Height=""1""/>
                                    <Rectangle Grid.Column=""1"" Grid.Row=""1"" Name=""IndentSpacer"" />
                                    <ToggleButton Grid.Column=""2"" Grid.Row=""1"" Name=""ExpanderButton"" Height=""15"" Width=""15"" Margin=""2,0,0,0"">
                                      <ToggleButton.Template>
                                        <ControlTemplate TargetType=""ToggleButton"">
                                          <Grid Background=""Transparent"">
                <vsm:VisualStateManager.VisualStateGroups>
                    <vsm:VisualStateGroup x:Name=""CommonStates"">
                        <vsm:VisualState x:Name=""Normal""/>
                        <vsm:VisualState x:Name=""MouseOver"">
                            <Storyboard>
                                <ColorAnimation Storyboard.TargetName=""CollapsedArrow"" Storyboard.TargetProperty=""(Stroke).Color"" Duration=""0"" To=""#FF6DBDD1""/>
                                <ColorAnimation Storyboard.TargetName=""ExpandedArrow"" Storyboard.TargetProperty=""(Fill).Color"" Duration=""0"" To=""#FF6DBDD1""/>
                            </Storyboard>
                        </vsm:VisualState>
                        <vsm:VisualState x:Name=""Pressed"">
                            <Storyboard>
                                <ColorAnimation Storyboard.TargetName=""CollapsedArrow"" Storyboard.TargetProperty=""(Stroke).Color"" Duration=""0"" To=""#FF6DBDD1""/>
                                <ColorAnimation Storyboard.TargetName=""ExpandedArrow"" Storyboard.TargetProperty=""(Fill).Color"" Duration=""0"" To=""#FF6DBDD1""/>
                            </Storyboard>
                        </vsm:VisualState>
                        <vsm:VisualState x:Name=""Disabled"">
                            <Storyboard>
                                <DoubleAnimation Duration=""0"" Storyboard.TargetName=""CollapsedArrow"" Storyboard.TargetProperty=""Opacity"" To="".5""/>
                                <DoubleAnimation Duration=""0"" Storyboard.TargetName=""ExpandedArrow"" Storyboard.TargetProperty=""Opacity"" To="".5""/>
                            </Storyboard>
                        </vsm:VisualState>
                    </vsm:VisualStateGroup>
                    <vsm:VisualStateGroup x:Name=""CheckStates"">
                        <vsm:VisualState x:Name=""Checked"" />
                        <vsm:VisualState x:Name=""Unchecked"">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Duration=""0"" Storyboard.TargetName=""CollapsedArrow"" Storyboard.TargetProperty=""Visibility"">
                                    <DiscreteObjectKeyFrame KeyTime=""0"" Value=""Visible""/>
                                </ObjectAnimationUsingKeyFrames>
                                <ObjectAnimationUsingKeyFrames Duration=""0"" Storyboard.TargetName=""ExpandedArrow"" Storyboard.TargetProperty=""Visibility"">
                                    <DiscreteObjectKeyFrame KeyTime=""0"" Value=""Collapsed""/>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </vsm:VisualState>
                    </vsm:VisualStateGroup>
                </vsm:VisualStateManager.VisualStateGroups>
    
                <Path Stretch=""Uniform"" Data=""F1 M 0,0 L 0,1 L .6,.5 L 0,0 Z"" Width=""5"" HorizontalAlignment=""Center"" VerticalAlignment=""Center"" x:Name=""CollapsedArrow"" Visibility=""Collapsed"" Stroke=""#FF414345""/>
                <Path Stretch=""Uniform"" Data=""F1 M 0,1 L 1,1 L 1,0 L 0,1 Z"" Width=""6"" HorizontalAlignment=""Center"" VerticalAlignment=""Center"" x:Name=""ExpandedArrow"" Fill=""#FF414345""/>
            </Grid>
              </ControlTemplate>
            </ToggleButton.Template>
            </ToggleButton>
                                    <Rectangle Grid.Column=""1"" Grid.ColumnSpan=""5"" Fill=""#FFD3D3D3"" Height=""1"" Grid.Row=""2""/>
                                    <Rectangle Name=""FocusVisual"" Grid.Column=""1"" Grid.ColumnSpan=""4"" Grid.RowSpan=""3"" Stroke=""#FF6DBDD1"" StrokeThickness=""1"" HorizontalAlignment=""Stretch"" 
                               VerticalAlignment=""Stretch"" IsHitTestVisible=""false"" Opacity=""0"" />
                                    <localprimitives:DataGridRowHeader Name=""RowHeader""  Grid.RowSpan=""3"" localprimitives:DataGridFrozenGrid.IsFrozen=""True""/>
    
                                </localprimitives:DataGridFrozenGrid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>";   
    

    This is where your cell content comes in, and again I have some dynamic columns so I need to add cells dynamically (no need to do this if your grid is static)

    <data:DataGridCell  Content=""{Binding Name}""/>
                                    <data:DataGridCell  Content=""""/>
                                    <data:DataGridCell  Content=""""/>
                                    <data:DataGridCell  Content=""""/>
                                    <data:DataGridCell  Content=""""/>
                                    <data:DataGridCell HorizontalContentAlignment=""Left"" Margin=""7,0,0,0"" Content=""{Binding Converter={StaticResource myConverter}, ConverterParameter=TotalScore}""/>" + colStr2 +    
    

    That is it pretty much, yes I agree it’s not a trivial job but it gives you custom style when you need it! Feel free to comment!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks for reading this. I have markup similar to what is below. Using the
Thanks for reading this. I would have thought it would be as simple as
Thanks for reading this. I imagine this is really a javascript question, and my
Thanks for reading. I'm a bit new to jQuery, and am trying to make
Thanks for reading this. I am dynamically generating some data which includes a select
Thanks for reading this I thought I could use find(), but couldn't make it
I'm reading about Rails fixtures in this guide (thanks, trevorturk). It appears you define
I have a problem I am trying to resolve. We have a SQL Server
I have a simple problem but I am not sure how to solve it.
As you may have guessed from the question - I am right at the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.