哪些事件触发按钮中的命令? [英] What event(s) trigger a command in a button?

查看:102
本文介绍了哪些事件触发按钮中的命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个与我正在从事的项目有关的问题:

so i have a question relating to a project i'm working on:

什么事件用于触发按钮控件中的命令?

what events are used to trigger a command in a button control? is it only the click event?

是因为仅单击事件吗?因为当我单击按钮时,释放鼠标按钮后我的命令将被执行吗?所以这就是为什么我想知道。

because when i click on a button my command will be executed after my mouse button is released? so thats why i want to know.

<Button x:Name="ClickButton" Content="Click here" HorizontalAlignment="Left" Margin="325,123,0,0" VerticalAlignment="Top" Width="75" Command="{Binding ClickHereCommand}"/>

ViewModel中的代码

Code in the ViewModel

  public ICommand ClickHereCommand => (new CommandHandler(() => IsGoingUp(), _canExecute));

    public void IsGoingUp()
    {
      Console.WriteLine("Moving up...");
    }


推荐答案

默认情况下,Command属性确实绑定到Click事件。您可以将Command属性绑定到其他事件,如下所示: https://stackoverflow.com/a/20356042/1166719

By default, the Command property is indeed bound to the Click event. You can bind your Command property to other events as shown here: https://stackoverflow.com/a/20356042/1166719.

尽管您只想将Command绑定到另一个鼠标事件,但ClickMode属性正是您要寻找的: https://msdn.microsoft.com/en -US / library / system.windows.controls.primitives.buttonbase.clickmode(v = vs.110).aspx

Though if you just want to bind your Command to another mouse event, the ClickMode property is what you're looking for: https://msdn.microsoft.com/en-US/library/system.windows.controls.primitives.buttonbase.clickmode(v=vs.110).aspx

这篇关于哪些事件触发按钮中的命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆