Reputation: 241
I have a requirement to monitor the topmost propertyvalue change on WPF Window. I am writing something like this:
static MainWindow()
{
TopmostProperty.OverrideMetadata(typeof(Window), new PropertyMetadata(new PropertyChangedCallback(Changed)));
}
public MainWindow()
{
InitializeComponent();
}
private static void Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
throw new NotImplementedException();
}
But I am getting this exception: he invocation of the constructor on type 'WpfApplication4.MainWindow' that matches the specified binding constraints threw an exception.' Line number '4' and line position '9'."
Upvotes: 1
Views: 1069
Reputation: 34293
Two mistakes:
The first argument of OverrideMetadata
must be your type.
The type of the second argument must be the same as in the base type.
TopmostProperty.OverrideMetadata(
typeof(MainWindow),
new FrameworkPropertyMetadata(Changed));
(Bonus) You don't need to override metadata if you just need change notification.
Upvotes: 5