How to create Custom Property for WPF DataGridTextColumn

六月ゝ 毕业季﹏ 提交于 2019-12-24 15:13:18

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/17969163/how-to-create-custom-property-for-wpf-datagridtextcolumn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!