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 ?
You need to use FrameworkPropertyMetadata
. All elements that ship with WPF that derive from FrameworkElement
(and DataGrid
does) use it as their metadata.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With