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

Ask A Question

Stats

  • Questions 83k
  • Answers 83k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can case all input into TextBox controls with the… May 11, 2026 at 4:46 pm
  • Editorial Team
    Editorial Team added an answer If I understand you correctly, you want to study the… May 11, 2026 at 4:46 pm
  • Editorial Team
    Editorial Team added an answer You can do one of a few things in desending… May 11, 2026 at 4:46 pm

Related Questions

I am trying to move my Joomla1 website from localhost to my bluehost.com domain.
I am in the early stages of planning and designing a custom accounting application
I have a custom UIView that generates a set of subviews and display them
I am trying to move a C# Compact Framework 1 application from Visual Studio

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.