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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:17:45+00:00 2026-06-14T09:17:45+00:00

I have the following xaml code defined for DataGridTextColumn of a DataGrid. <DataGridTextColumn x:Name=UserIdColumn

  • 0

I have the following xaml code defined for DataGridTextColumn of a DataGrid.

<DataGridTextColumn x:Name="UserIdColumn" Binding="{Binding Path=UserId}" HeaderStyle="{StaticResource DataGridHeaderStyle}"/>

And Here is the HeaderStyle for the DataGridTextColumn

<Style x:Key="DataGridHeaderStyle" TargetType="{x:Type DataGridColumnHeader}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="DataGridColumnHeader">
                <StackPanel>
                    <TextBlock x:Name="ColumnName" Text="UserId" />
                    <TextBox x:Name="UserIdFilter" Width="100">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="TextChanged">
                                <cal:ActionMessage MethodName="UserIdFilterChanged">
                                    <cal:Parameter Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridTextColumn}}, Path=Name}"/>
                                    <cal:Parameter Value="{Binding ElementName=UserIdFilter, Path=Text}" />
                                </cal:ActionMessage>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </TextBox>
                </StackPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>    

As one can see I am trying to access the DataGridTextColumn’s Name property inside the DataGridColumnHeader’s ControlTemplate using this line of code

<cal:Parameter Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridTextColumn}}, Path=Name}"/>

The above line is returning null, why ?

Is there any other way to get hold of DataGridTextColumn’s Name property from DataGridColumnHeader’s control template ?

  • 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-14T09:17:46+00:00Added an answer on June 14, 2026 at 9:17 am

    You are recovering a null value for 2 different reasons:
    The first one is that the DataGridTextColumn is not part of the visual tree and is not a visual instance of the datagrid. This is just an instance that descibes how a column of the datagrid should be displayed. Thus, DataGridTextColumn is not part of the ancestors of you cell.
    The only way I see to recover your DataGridTextColumn is to proceed somehow like that:

    <TextBox x:Name="UserIdFilter" Width="100" Tag="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}, Path=Columns[0]}">
    

    This way, you should set the Tag property of the Textbox with the instance of the DataGridTextColumn (you can check with snoop that it works properly)

    Then, the second reason explaining why you have a null value is that the DataGridTextColumn has no Name property.
    What you could do is simply create an attached property like this one:

    public class XamlHelper
    {
        public static readonly DependencyProperty NameProperty = DependencyProperty.RegisterAttached("Name", typeof(string), typeof(XamlHelper));
    
        public static string GetName(DependencyObject obj)
        {
            return (string)obj.GetValue(NameProperty);
        }
    
        public static void SetName(DependencyObject obj, string value)
        {
            obj.SetValue(NameProperty, value);
        }
    }
    

    … replace the name of the column definition by this one:

    <DataGridTextColumn alias:XamlHelper.Name="UserIdColumn" Binding="{Binding Path=UserId}" HeaderStyle="{StaticResource DataGridHeaderStyle}"/>
    

    and retrieve the property this way:

    <Style x:Key="DataGridHeaderStyle" TargetType="{x:Type DataGridColumnHeader}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="DataGridColumnHeader">
                    <StackPanel>
                        <TextBlock x:Name="ColumnName" Text="UserId" />
                        <TextBox x:Name="UserIdFilter" Width="100"  Tag="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}, Path=Columns[0]}">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="TextChanged">
                                    <cal:ActionMessage MethodName="UserIdFilterChanged">
                                        <cal:Parameter Value="{Binding ElementName=UserIdFilter, Path=Tag.(alias:XamlHelper.Name)}"/>
                                        <cal:Parameter Value="{Binding ElementName=UserIdFilter, Path=Text}" />
                                    </cal:ActionMessage>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </TextBox>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>   
    

    … hope I didn’t made too much mistakes in this code but I think something like that should work

    Notice that I used the tag property of the textbox has a buffer because I am note sure the findAncestor mode of the binding is able to recover the datagrid properly (I had some issues on elements that are not is the visual tree). Maybe having a unique binding in you parameter also work…

    Tag is also great to make tests because it allows to see the value in snoop!

    Do not hesitate if some points are not clear enougth

    edit:
    I checked out the DataGridCOlumnHeaderClass and I discovered the property that seems to contain what you expected…
    Thus, it should be possible to do that:

    <Style x:Key="DataGridHeaderStyle" TargetType="{x:Type DataGridColumnHeader}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="DataGridColumnHeader">
                    <StackPanel>
                        <TextBlock x:Name="ColumnName" Text="UserId" />
                        <TextBox x:Name="UserIdFilter" Width="100"  Tag="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridColumnHeader}}, Path=Column}">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="TextChanged">
                                    <cal:ActionMessage MethodName="UserIdFilterChanged">
                                        <cal:Parameter Value="{Binding ElementName=UserIdFilter, Path=Tag.(alias:XamlHelper.Name)}"/>
                                        <cal:Parameter Value="{Binding ElementName=UserIdFilter, Path=Text}" />
                                    </cal:ActionMessage>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </TextBox>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XAML Code: <sdk:DataGrid Margin=58,8,52,18 Name=dataGridTickets> <sdk:DataGrid.Columns> <sdk:DataGridTextColumn x:Name=ticketNoColumn Header=Ticket No.
I have a following XAML: <ComboBox Name=groupComboBox ItemsSource={Binding Path=MyServiceMap.Groups} DisplayMemberPath={Binding Name}/> In the code
I have the following xaml-Code: <Border x:Name=border> <Border.Style> <Style TargetType={x:Type Border}> <Style.Triggers> <DataTrigger Binding={Binding
I have the following column defined in my xaml code <telerik:GridViewMaskedTextBoxColumn Mask=P1 MaskType=Numeric DataMemberBinding={Binding
I have the following XAML code: <phone:PhoneApplicationPage.ApplicationBar> <shell:ApplicationBar IsVisible=True IsMenuEnabled=False x:Name=PageBar> <shell:ApplicationBarIconButton IconUri=/Assets/Icons/appbar.questionmark.rest.png Text=Help
I have a resource (myPoint) defined in XAML as follows: <Path Name=myPath> <Path.Resources> <Point
I have the following XAML code as part of a custom control: <telerik:RadTreeView x:Name=treeModules>
Hi I have following XAML code which is the output from XamlWriter.Save(): <StackPanel Name=itemStack
I am NEW to WPF. I have the following XAML code: </Window> ... <Canvas>
I have the following code: <Window x:Class=kkk.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=350 Width=525> <Window.Resources> <Style

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.