在MainWindow外定义事件处理程序?

时间:2017-06-09 14:10:16

标签: wpf

我试图在auser类中定义一些事件处理程序,但我不知道如何。 MainWindow需要处理程序定义。

  public abstract partial class MainWindow: Window {
     public User user = new User();
  }

  public class User {
    internal void ExampleMouseEventDown(object sender, MouseEventArgs e) {
      // Does stuff;
    }
  }

有没有办法以某种方式使这项工作?如:

mainWindow.AddHandleDefinition += ExampleMouseEventDown();

还试过这个:

public partial class MainWindow : Window {
    public MainWindow() {
        User user = new User(this);
    }
}

public class User
{
    internal User(MainWindow w)
    {
        w.AddObserverButton.MouseUp += ExampleMouseEventDown;
    }
    internal void ExampleMouseEventDown(object sender, MouseEventArgs e)
    {
        // Does stuff;
    }
}

0 个答案:

没有答案