Avinash Singh
Avinash Singh

Reputation: 2785

How to create Custom Property for WPF DataGridTextColumn

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.

Upvotes: 1

Views: 1831

Answers (1)

Avinash Singh
Avinash Singh

Reputation: 2785

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();

Upvotes: 3

Related Questions