WPF 中可以设置鼠标监听器吗?

发布于 2024-08-18 17:06:00 字数 30 浏览 3 评论 0原文

我可以在 WPF 中设置鼠标监听器(单击)吗?

Can i set a mouselistener (Clicked) in WPF?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

荆棘i 2024-08-25 17:06:00

简单,

  • 只需为您的 xaml 控件添加一个 Click 属性
  • 为其分配一个处理程序
  • 在您的 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 中的WPF 支持的鼠标事件列表< /a>

Simple,

  • Just a Click attribute to your xaml control
  • Assign it a handler
  • Define the handler in your xaml.cs

In your xaml,

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

In your xaml.cs,

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

There are loads of mouse events available. Check MSDN for the list of mouse events supported in WPF

乄_柒ぐ汐 2024-08-25 17:06:00

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

If te user clicked where?
If you have a button(or window or pretty much anything else) you simpy add the MouseDown() eventhandler....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文