问题
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