我试图在派生类中覆盖 ItemsControl.ItemsSourceProperty 的元数据,以便分配我自己的回调:
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)
{}
}
我得到一个设计器+运行时异常:
Metadata override and base metadata must be of the same type
我究竟做错了什么 ?