0

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?

FLCL
  • 2,445
  • 2
  • 24
  • 45
  • have you tried EventSetter in the ListBox's Style? – Bizhan Nov 24 '14 at 10:44
  • Possible duplicate of http://stackoverflow.com/questions/6430256/wpf-event-binding-to-viewmodel-for-non-command-classes – Bizhan Nov 24 '14 at 10:48
  • @Bizz, there is no word about static properties there, but the answer to that question is correct for me too. – FLCL Nov 24 '14 at 10:52

1 Answers1

0

The problem was solved simply by calling my custom handler from standard generated method.

FLCL
  • 2,445
  • 2
  • 24
  • 45