eran otzap
eran otzap

Reputation: 12533

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 ?

Upvotes: 24

Views: 3285

Answers (1)

Abe Heidebrecht
Abe Heidebrecht

Reputation: 30498

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

Upvotes: 41

Related Questions