如何为WPF DataGridTextColumn创建自定义属性 [英] How to create Custom Property for WPF DataGridTextColumn
本文介绍了如何为WPF DataGridTextColumn创建自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在WPF DataGridTextColumn中添加自定义属性,
I want to add custom property in WPF DataGridTextColumn,
我如何添加自定义属性,并将其与C#代码绑定并通过C#代码检索。
How i can add custom property, and Bind it from C# code and retrieve it by C# code.
推荐答案
我刚刚得到了答案
首先创建
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#的绑定标签属性
For Binding tag property by C#
DataGridTextColumn clm = new DataGridTextColumn();
dataGridTag.SetTag(clm, "TagValue");
通过C#检索标签属性
DataGridColumn clm1 = dgQuestionTemplate.CurrentCell.Column as DataGridColumn;
string strQType= dataGridTag.GetTag(clm1).ToString();
这篇关于如何为WPF DataGridTextColumn创建自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文