2013-07-31 70 views
1

我想在WPF DataGridTextColumn添加自定義屬性,如何創建自定義屬性爲WPF DataGridTextColumn

如何,我可以添加自定義屬性,並從C#代碼綁定它和C#代碼檢索。

+0

爲什麼會用C#

 DataGridTextColumn clm = new DataGridTextColumn(); dataGridTag.SetTag(clm, "TagValue"); 

綁定標籤屬性檢索標記屬性你想要一個Tag屬性?將它命名爲更方便一些? – Bas

+0

的[在WPF DataGrid列標籤屬性]可能的複製(http://stackoverflow.com/questions/11535894/tag-property-in-wpf-datagrid-column) –

回答

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#

  DataGridColumn clm1 = dgQuestionTemplate.CurrentCell.Column as DataGridColumn; 

     string strQType= dataGridTag.GetTag(clm1).ToString(); 
相關問題