我想在WPF DataGridTextColumn中添加自定义属性,
如何添加自定义属性,并将其与C#代码绑定并通过C#代码检索它。
答案 0 :(得分:3)
我刚刚得到答案
首先创建
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);
}
}
对于C#
的绑定标记属性 DataGridTextColumn clm = new DataGridTextColumn();
dataGridTag.SetTag(clm, "TagValue");
用于通过C#
检索标记属性 DataGridColumn clm1 = dgQuestionTemplate.CurrentCell.Column as DataGridColumn;
string strQType= dataGridTag.GetTag(clm1).ToString();