1

I want to add custom property in WPF DataGridTextColumn,

How i can add custom property, and Bind it from C# code and retrieve it by C# code.

Avinash Singh
  • 2,697
  • 11
  • 44
  • 72
  • Why would you want a Tag property? Name it something more convenient maybe? – Bas Jul 31 '13 at 12:31
  • Possible duplicate of [Tag Property in WPF DataGrid Column](http://stackoverflow.com/questions/11535894/tag-property-in-wpf-datagrid-column) – g t May 04 '17 at 07:54

1 Answers1

3

I just got answer for it

First Create

 public static class dataGridTag
    {
        public static readonly DependencyProperty TagProperty = DependencyProperty.RegisterAttached(
           "Tag",
           typeof(object),
           typeof(dataGridTag),
           new FrameworkPropertyMetadata(null));

        public static object GetTag(DependencyObject dependencyObject)
        {
            return dependencyObject.GetValue(TagProperty);
        }

        public static void SetTag(DependencyObject dependencyObject, object value)
        {
            dependencyObject.SetValue(TagProperty, value);
        } 
    }

For Binding tag property by C#

         DataGridTextColumn clm = new DataGridTextColumn();
         dataGridTag.SetTag(clm, "TagValue");

For Retrieving tag property by C#

         DataGridColumn clm1 = dgQuestionTemplate.CurrentCell.Column as DataGridColumn;

         string strQType=  dataGridTag.GetTag(clm1).ToString();
Avinash Singh
  • 2,697
  • 11
  • 44
  • 72