2013-03-19 40 views
0

我有一個從網格繼承的自定義控件。在那個控件中,我有一個ColumnHeaders列表(從Label繼承的控件)。但列表不起作用。ColumnHeaders在xaml中定義。列表在自定義控件中沒有得到更新

代碼

public List<ColumnHeader> ColumnHeaders { get { return (List<ColumnHeader>)GetValue(ColumnHeadersProperty); } set { SetValue(ColumnHeadersProperty, value); } } 

public static readonly DependencyProperty ColumnHeadersProperty = DependencyProperty.Register("ColumnHeaders", typeof(List<ColumnHeader>), typeof(DataGrid), 
      new FrameworkPropertyMetadata(new List<ColumnHeader>(), FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsParentMeasure, OnColumnHeadersChanged)); 



<lib:DataGrid Columns="9" Rows="16" x:Name="mVersions" RowHeader="True" ColumnHeader="True" ColumnEnter="ColumnEnter" Background="Transparent"> 
    <lib:DataGrid.ColumnHeaders> 
     <lib:ColumnHeader Content="Bedieningsb." /> 
     <lib:ColumnHeader Content="LCD" /> 
     <lib:ColumnHeader Content="Herhaalb." /> 
     <lib:ColumnHeader Content="Relais" /> 
     <lib:ColumnHeader Content="Printer" /> 
     <lib:ColumnHeader Content="Voedingscontr." /> 
     <lib:ColumnHeader Content="Redundantie" /> 
     <lib:ColumnHeader Content="WebModule" /> 
     <lib:ColumnHeader Content="Net" /> 
    </lib:DataGrid.ColumnHeaders> 
</lib:DataGrid> 

功能OnColumnHeadersChanged不會被調用。爲什麼??但其他屬性正在更新網格。

+0

使用'ObservableCollection',而不是'List' – MarcinJuraszek 2013-03-19 10:37:15

+0

的ObservableCollection也不起作用 – Calypoter 2013-03-19 11:01:46

+0

有沒有一個知道我怎麼能得到它的工作試試? – Calypoter 2013-03-21 10:07:16

回答

0

您可以使用此代碼

public static readonly DependencyProperty ColumnHeadersProperty = DependencyProperty.Register("ColumnHeaders", typeof(List<ColumnHeader>), typeof(DataGrid), 
    new PropertyMetadata(OnColumnHeadersChanged)); 
+0

我得到一個沒有默認值的nullexception,並且默認值的結果與以前相同 – Calypoter 2013-03-19 11:53:51