There is a static object SomeClass.Current in my app which has property MySelectionChangedEvent. In WPF I need to bind ListBox SelectionChanged event to this subproperty. For not-a-handler properties of the static object this binding works correctly, but not for the handler:
<ListBox SelectionChanged="{Binding Path=MySelectionChangedEvent, Source={x:Static SomeClass.Current}}" ...></ListBox>
, I tried to declare MySelectionChangedEvent in these ways:
public EventHandler<SelectionChangedEventArgs> MySelectionChangedEvent{get;set;}
or
public event EventHandler<SelectionChangedEventArgs> MySelectionChangedEvent;
or
public static readonly DependencyProperty MySelectionChangedEventProperty =
DependencyProperty.Register("MySelectionChangedEvent",
typeof(EventHandler<SelectionChangedEventArgs>),
typeof(SomeClass),
new PropertyMetadata(new EventHandler<SelectionChangedEventArgs>((s, e) => { })));
But everything leads to runtime error:
Cannot find DependencyProperty or PropertyInfo for property named 'MySelectionChangedEvent'. Property names are case sensitive. Error at object 'System.Windows.Controls.ListBox' in markup file 'DbEditor;component/...'
What is correct way to bind event handler to property(or field) of a static object?