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 6792243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:56:43+00:00 2026-05-26T17:56:43+00:00

Possible Duplicate: Wpf Toolkit. Bind DataGrid Column Header to DynamicResource WPF Error: Cannot find

  • 0

Possible Duplicate:
Wpf Toolkit. Bind DataGrid Column Header to DynamicResource
WPF Error: Cannot find govering FrameworkElement for target element

I am creating a WPF application using the MVVM pattern, so on my view I am trying to bind the column header of a DataGrid column to a property on my view model which is the data context of the view that the DataGrid is in.

XAML:

<DataGrid Name="DailyData" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" ItemsSource="{Binding Path=DailyDataViewModels}" HorizontalAlignment="Stretch">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="{Binding InflowVolumeLabel}" Binding="{Binding InflowVolume}"></DataGridTextColumn>
                    </DataGrid.Columns>
                </DataGrid>

However the header just shows up blank and does not seem to be trying to bind to the specified property, how can you bind a DataGrid column header?

  • 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-26T17:56:44+00:00Added an answer on May 26, 2026 at 5:56 pm

    You’ve run into a neat problem with the DataGrid.Columns collection, namely they are not a member of the same visual tree and thus only the Binding property appears to work.

    The only approach I’ve found that works is to add an attached property to the DataGrid which will apply the headers after the data is loaded.

    public static readonly DependencyProperty ColumnHeadersProperty =
        DependencyProperty.RegisterAttached(
            "ColumnHeaders",
            typeof(IDictionary<string, string>),
            typeof(DataGrid),
            new UIPropertyMetadata(
                new Dictionary<string,string>(),
                ColumnHeadersPropertyChanged));
    
    public static IDictionary<string,string> GetColumnHeaders(DependencyObject obj)
    {
        return (IDictionary<string, string>)obj.GetValue(ColumnHeadersProperty);
    }
    
    public static void SetColumnHeaders(DependencyObject obj,
        IDictionary<string, string> value)
    {
        obj.SetValue(ColumnHeadersProperty, value);
    }
    
    static void ColumnHeadersPropertyChanged(DependencyObject sender,
        DependencyPropertyChangedEventArgs e)
    {
        var dataGrid = sender as DataGrid;
        if (dataGrid != null && e.NewValue != null)
        {
            dataGrid.AutoGeneratingColumn += AddColumnHeaders;
        }
    }
    
    static void AddColumnHeaders(object sender,
        DataGridAutoGeneratingColumnEventArgs e)
    {
        var headers = GetColumnHeaders(sender as DataGrid);
        if (headers.ContainsKey(e.PropertyName))
        {
            e.Column.Header = headers[e.PropertyName];
        }
    }
    

    Potentially used like (could be improved):

    // you could change it to use Column.DisplayIndex
    this.dataGrid.SetValue(
        DataGridEx.ColumnHeadersProperty,
        new Dictionary<string, string>
        {
            { "PropertyName1", "Header 1" },
            { "PropertyName2", "Header 2" },
            { "PropertyName3", "Header 3" },
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: C#/WPF: Toolkit DataGrid - Transpose rows and columns I would like to
Possible Duplicate: XAML Binding Properties I was wondering how in WPF do you bind
Possible Duplicate: In WPF, what are the differences between the x:Name and Name attributes?
Possible Duplicate: What WPF books would you recommend? GUI's written using WPF seem to
I'm using the WPF Toolkit's DataGrid to display a set of search results. As
Possible Duplicate: Drag WPF Popup control I created a WPF popup control in my
Possible Duplicate: No Main() in WPF? This is the code for Main() in WPF
Possible Duplicate: Code to check if a cell of a DataGrid is currently edited
Possible Duplicate: XAML Conditional Compilation I am new to WPF. I just need to
Possible Duplicate: How can one host Flash content in a WPF application and use

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.