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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:21:53+00:00 2026-05-11T13:21:53+00:00

I am trying to move custom DataGrid column definition into a UserControl. MyComboBoxColumn.xaml <dg:DataGridTemplateColumn

  • 0

I am trying to move custom DataGrid column definition into a UserControl.

MyComboBoxColumn.xaml

<dg:DataGridTemplateColumn      x:Class='WpfDecomposition.MyComboBoxColumn'     xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'     xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'     xmlns:dg='clr-namespace:Microsoft.Windows.Controls;assembly=WpfToolkit'     x:Name='_this'     >      <dg:DataGridTemplateColumn.Header>         <Button Content='{Binding MyHeader, ElementName=_this}' ></Button>     </dg:DataGridTemplateColumn.Header>  </dg:DataGridTemplateColumn> 

MyComboBoxColumn.cs

public partial class MyComboBoxColumn : DataGridTemplateColumn {     public MyComboBoxColumn()     {         InitializeComponent();     }      public static DependencyProperty MyHeaderProperty =          DependencyProperty.Register('MyHeader', typeof(string), typeof(MyComboBoxColumn), new PropertyMetadata('TEST')); } 

Main windows XAML:

<dg:DataGrid CanUserAddRows='True' AutoGenerateColumns='False'>     <dg:DataGrid.Columns>         <my:MyComboBoxColumn />     </dg:DataGrid.Columns> </dg:DataGrid> 

I would expect to see a button ‘TEST’ in the column’s header, but instead I see the empty button. Looks like the binding is broken. What is wrong?

  • 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. 2026-05-11T13:21:54+00:00Added an answer on May 11, 2026 at 1:21 pm

    It’s not working because it can’t find an element with the name _this. I get the following error in the Output window when I debug your code in Visual Studio:

    System.Windows.Data Error: 4 : Cannot find source for binding with reference ‘ElementName=_this’. BindingExpression:Path=MyHeader; DataItem=null; target element is ‘Button’ (Name=’TestButton’); target property is ‘Content’ (type ‘Object’)

    As for why it can’t find it – I think that is because WPF bindings use the visual tree to find the source of the binding. In this case, the MyComboBoxColumn is not in the visual tree, so therefore it can’t find an element with that name.

    I also tried using RelativeSource to find the element, but that didn’t work either – likely for the same reason.

    The only thing that I could get to work is to set the DataContext of the button to the column itself in the constructor:

    public MyComboBoxColumn() {     InitializeComponent();      this.TestButton.DataContext = this; } 

    And then change the binding in the XAML:

    <tk:DataGridTemplateColumn.Header>     <Button Content='{Binding Path=MyHeader}' x:Name='TestButton' /> </tk:DataGridTemplateColumn.Header> 

    That doesn’t seem like the best way to do it, but at least it works.

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

Sidebar

Related Questions

I am trying to move some custom drawing code from a view into a
Trying to move some divs using hover, this is my markup: <div class=item dark-grey>
I'm trying to slide some (custom) tab-like buttons into view. I don't want them
I want to have a Custom DataGrid which can, Move to next cell when
I'm trying to build custom AuthorizeAttribute, so in my Core project (a class library)
I'm trying to implement a custom UISlider, I've extended it with a class called
I am trying to move some files in python, but they have spaces in
I am trying to move even numbers in an array to the front and
I am trying to move an object by checking if the mouse is colliding
I am trying to move the logic to the very high-level from the db.

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.