代码之家  ›  专栏  ›  技术社区  ›  rakete

是否可以在WPF中设置mouseListener?

  •  0
  • rakete  · 技术社区  · 15 年前

    我可以在wpf中设置一个mouselistener(单击)吗?

    2 回复  |  直到 11 年前
        1
  •  2
  •   sudarsanyes    15 年前

    简单的,

    • 只是一个 点击 XAML控件的属性
    • 给它分配一个处理程序
    • 在xaml.cs中定义处理程序

    在你的XAML中,

    <Button Click="Button_Click"></Button>
    

    在您的xaml.cs中,

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //What should be done when you click the control
        }
    

    有很多鼠标事件可用。检查msdn list of mouse events supported in WPF

        2
  •  1
  •   synepis    15 年前

    如果用户点击了哪里? 如果您有一个按钮(或窗口或其他几乎所有东西),您只需添加mousedown()事件处理程序…

    推荐文章