3

I want to create a static class where I will have some common methods which I will using in events. So for example I did a following class:

public static class CommonMethodsProvider {

    public static void CommonEventHandler( object sender, MouseButtonEventArgs e ) {
        // ...
    }

}

And in xaml code I tried to do it like that:

<... Handler="CommonMethodsProvider.CommonEventHandler" ... />

Is there any way to use it in WPF controls?

I receive error:

PreviewMouseLeftButtonDown="CommonMethodsProvider.CommonEventHandler" is not valid. 'CommonMethodsProvider.CommonEventHandler' is not a valid event handler method name. Only instance methods on the generated or code-behind class are valid.

So isn't there any opportunity to do it?

nosbor
  • 2,826
  • 3
  • 39
  • 63
  • pls take a look at this link http://stackoverflow.com/questions/5761114/call-events-or-methods-located-in-a-class-from-xaml – Glory Raj Nov 15 '11 at 21:41
  • Its more about behaviors, but I need as simple as it is possible solution to make this event running method from external Class. – nosbor Nov 15 '11 at 21:55

1 Answers1

0

In the constructor, in the code behind, after InitializeComponent(); add lines such as

MyControl.PreviewMouseLeftButtonDown += CommonMethodsProvider.CommonEventHandler;
Eray Balkanli
  • 7,752
  • 11
  • 48
  • 82
Shuggie
  • 11