Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Metadata override and base metadata must be of the same type

I'm trying to override the metadata of ItemsControl.ItemsSourceProperty in a derived class in order to assign my own callback :

 public class CustomDataGrid : System.Windows.Controls.DataGrid
 {
    static CustomDataGrid()
    {
        CustomDataGrid.ItemsSourceProperty.OverrideMetadata(typeof(CustomDataGrid), new UIPropertyMetadata(new PropertyChangedCallback(OnItemsSourcePropertyChanged)));
    }

    private static void OnItemsSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {}
 }

I get a designer + runtime exception :

Metadata override and base metadata must be of the same type

What am I doing wrong ?

like image 911
eran otzap Avatar asked Aug 13 '13 13:08

eran otzap


1 Answers

You need to use FrameworkPropertyMetadata. All elements that ship with WPF that derive from FrameworkElement (and DataGrid does) use it as their metadata.

like image 137
Abe Heidebrecht Avatar answered Oct 22 '22 01:10

Abe Heidebrecht