覆盖命令 [英] Overriding the Command

查看:92
本文介绍了覆盖命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

命令的当前定义:

public Icommand  MyCommand

{

   get { return myCommand;}

   set{ SetProperty(ref myCommand, value, "MyCommand");}

}


在班上使用MyCommand:

Using MyCommand in my class:

public DelegateCommand OnMyCommandClicked{get;set;}

MyCommand = OnMyCommandClicked;


在我的类构造函数中:

OnMyCommandClicked = new DelegateCommand(MyCommndClickExecuted);


课堂上:

private void MyCommndClickExecuted(object sender)

{



}

但是我该如何更改MyCommand Click Executed这样呢? :

But how can i change the MyCommand Click Executed like this ? :

private void MyCommndClickExecuted(object sender, RoutedEventArgs e)

{

}


推荐答案


嗨wpf_xam1,


Hi   wpf_xam1,

据我所知,命令为视图提供了一种机制来更新MVVM体系结构中的模型.命令提供了一种在元素树中搜索命令处理程序的方法.

As far as I know, Commands provide a mechanism for the view to update the model in the MVVM architecture. Commands provide a way to search the element tree for a command handler.

可以通过"CommandParameter"传递参数.财产.单击按钮后,所选地址值将传递到ICommand. CommandParameter同时发送到CanExecute和Execute事件.

A parameter can be passed through the "CommandParameter" property. Once the button is clicked the selected address value is passed to the ICommand. The CommandParameter is sent to both CanExecute and Execute events.

>>但是如何更改MyCommand Click Executed这样执行? :

据我所知,没有任何直接的方法可以做到这一点.但这可以通过使用交互性EventTrigger并定义自己的TriggerAction来捕获EventArgs并作为CommandParameter发送来实现.

As far as I know, there is no any straight forward way of doing this. But this can be achieved using interactivity EventTrigger and defining your own TriggerAction to capture the EventArgs and send as CommandParameter.

您可以参考以下帖子.它将命令附加到Routed事件,并将RoutedEventArgs作为该命令的execute方法的参数.

You can refer the following post. It attached a command to a Routed event, give the RoutedEventArgs as parameter to this command's execute method.

使用MVVM和Interactivity框架在命令参数中传递放置事件数据:

Passing drop event data in a command parameter using MVVM and the Interactivity framework:
http://social.msdn.microsoft.com/Forums/silverlight/en-US/5cd586e7-640f-447b-9040-e9270173abf7/passing-drop-event-data-in-a-command-parameter-using-mvvm-and-the-interactivity-framework

最好的问候,

Yohann Lu

Yohann Lu


这篇关于覆盖命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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