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

  • SEARCH
  • Home
  • 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 7743113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:26:52+00:00 2026-06-01T09:26:52+00:00

I am using a DataGrid from the WpfToolkit. I have taken the Style resource

  • 0

I am using a DataGrid from the WpfToolkit. I have taken the Style resource dictionary for it and tweaked it a bit. What I am trying to accomplish is to make the header bold when a certain property on the data-bound object is True. The Column Header is not necessarily a TextBlock and has its Control Template redefined as seen below:

DataGridStyle:

<Style x:Key="ModificationsDataGridStyle"  TargetType="{x:Type compCtrls:ModDataGrid}">
    <Setter Property="ColumnHeaderStyle" Value="{StaticResource DatagridColumnHeaderCustomTemplateStyle}" />
</Style>

ColumnHeaderStyle:

<Style x:Key="DatagridColumnHeaderCustomTemplateStyle" 
       TargetType="{x:Type primitives:DataGridColumnHeader}">
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="MinWidth" Value="0" />
    <Setter Property="MinHeight" Value="28" />
    <Setter Property="Foreground" Value="White" />
    <Setter Property="FontWeight" Value="Normal" />
    <Setter Property="Cursor" Value="Hand" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type primitives:DataGridColumnHeader}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Border x:Name="BackgroundBorder" BorderThickness="0,1,0,1" 
                            Background="{StaticResource DataGridHeaderBackgroundBrush}" 
                            BorderBrush="{StaticResource DataGridHeaderBorderBrush}" 
                            Grid.ColumnSpan="2" />
                    <ContentPresenter x:Name="ContentPres" Margin="6,3,6,3" VerticalAlignment="Center" />
                    <Path x:Name="SortArrow" Visibility="Hidden" Data="M0,0 L1,0 0.5,1 z" Stretch="Fill" 
                          Grid.Column="1" Width="10" Height="7" Fill="White" Margin="0,0,7,0" 
                          VerticalAlignment="Center" RenderTransformOrigin="0.5,0.4" />
                    <Rectangle Width="1" Fill="#AAC377" HorizontalAlignment="Right" Grid.ColumnSpan="2" />

                    <Rectangle Width="1" Margin="0,0,1,0" Fill="#425B10" 
                               HorizontalAlignment="Right" Grid.ColumnSpan="2" />
                    <Thumb x:Name="PART_LeftHeaderGripper" HorizontalAlignment="Left" 
                           Style="{StaticResource ColumnHeaderGripperStyle}"/>
                    <Thumb x:Name="PART_RightHeaderGripper" HorizontalAlignment="Right" 
                           Style="{StaticResource ColumnHeaderGripperStyle}"/>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="SortDirection" Value="{x:Null}">
                        <Setter TargetName="SortArrow" Property="Visibility" Value="Collapsed" />
                    </Trigger>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" TargetName="BackgroundBorder" 
                                Value="{StaticResource DataGridHeaderMouseOverBackgroundBrush}" />
                        <Setter Property="BorderBrush" TargetName="BackgroundBorder" 
                                Value="{StaticResource DataGridHeaderBorderBrush}" />
                    </Trigger>
                    <Trigger Property="SortDirection" Value="Ascending">
                        <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                        <Setter TargetName="SortArrow" Property="Fill" Value="Goldenrod" />
                        <Setter TargetName="SortArrow" Property="RenderTransform">
                            <Setter.Value>
                                <RotateTransform Angle="180" />
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <Trigger Property="SortDirection" Value="Descending">
                        <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                        <Setter TargetName="SortArrow" Property="Fill" Value="Brown" />
                    </Trigger>
                    <Trigger Property="DisplayIndex" Value="0">
                        <Setter Property="Visibility" Value="Collapsed" 
                                TargetName="PART_LeftHeaderGripper"></Setter>
                    </Trigger>
                    <DataTrigger Binding="{Binding IsRevisedSummableField}" Value="True">
                        <Setter TargetName="ContentPres" Property="Control.FontWeight" Value="Bold" />
                    </DataTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

I thought using a DataTrigger (bound to the given property) in the template would work. Either I am wrong or have not gone the right path in implementing this. I should also mention that the columns are Auto-Generated and once the columns are generated, I set the datacontext of each DataGridColumn as such:

    protected override void OnAutoGeneratedColumns(EventArgs e)
    {
        var dataTable = pivotMod.DataTable;
        foreach (DataGridColumn gridCol in Columns)
        {
            var colName = gridCol.Header.ToString();
            DataColumn col = dataTable.Columns[colName];

            // give the column headers a pretty name
            gridCol.Header = col.Caption;

            // set the datacontext of the gridcolumn to the modfield ...
            ModFieldGUIWrapper modField = col.ExtendedProperties["ModField"] as ModFieldGUIWrapper;
            gridCol.SetValue(FrameworkElement.DataContextProperty, modField);
        }
        base.OnAutoGeneratedColumns(e);
    }

Any help is as always greatly appreciated.

Cheers,
Sean

  • 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-06-01T09:26:53+00:00Added an answer on June 1, 2026 at 9:26 am

    Found the reason why:

    I should have set the DataGridColumn.Header to the data object that contains the property specified in the DataTrigger in order to function properly. Then, I just overrided the ToString() method of my data class to display the pretty name that I wanted.

    protected override void OnAutoGeneratedColumns(EventArgs e)
        {
            var dataTable = pivotMod.DataTable;
            foreach (DataGridColumn gridCol in Columns)
            {
                var colName = gridCol.Header.ToString();
                DataColumn col = dataTable.Columns[colName];
    
                // set the datacontext of the gridcolumn to the modfield ...
                ModFieldGUIWrapper modField = col.ExtendedProperties["ModField"] as ModFieldGUIWrapper;
                gridCol.SetValue(FrameworkElement.DataContextProperty, modField);
    
                // set the header to the data object so that the datatrigger's binding works!!
                gridCol.Header = modField;
    
            }
            base.OnAutoGeneratedColumns(e);
        }
    

    Thanks to Chris W. your comment set me on the right path! 🙂

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

Sidebar

Related Questions

I'm using a Datagrid from the WPFtoolkit and am running into a problem with
I have a WPF Datagrid populated with data from one SQL table using Entity
I'm using a the WPF datagrid from the Microsoft CodePlex project. I have a
I'm using the datagrid from the WPF Toolkit for 3.5. I have a need
I am using the WPF Datagrid from Codeplex. I am able to style the
Am using silverlight 4.0 ,here am trying to export the data from datagrid to
I am using Toolkit DataGrid. There is a custom header style when user sorts
Using a DataGrid from WPFToolkit, I bind it to a datatable. On certain scenario
I have a Silverlight application that is using a DataGrid. Inside of that DataGrid
We have custom headers in the Silverlight DataGrid using the ContentTemplate. We've got a

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.