Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用EventToCommand和Devexpress将数据传递给ViewModel_Devexpress_Eventtocommand - Fatal编程技术网

使用EventToCommand和Devexpress将数据传递给ViewModel

使用EventToCommand和Devexpress将数据传递给ViewModel,devexpress,eventtocommand,Devexpress,Eventtocommand,我正在使用devexpress winform控件,目前我已在视图构造函数中定义了RowDoubleClick事件,如下所示: mvvmContext1.WithEvent<MyViewModel, RowClickEventArgs>(gridView1, "RowClick") .EventToCommand(x => x.Show(), v => (v.Clicks == 2) && (v.Button

我正在使用devexpress winform控件,目前我已在视图构造函数中定义了RowDoubleClick事件,如下所示:

mvvmContext1.WithEvent<MyViewModel, RowClickEventArgs>(gridView1, "RowClick")
            .EventToCommand(x => x.Show(),
            v => (v.Clicks == 2) && (v.Button == MouseButtons.Left));
当我双击该行时,会出现messagebox并打印“row Clicked”,但我也想在这个show方法中获取行数据(学生类型)

我如何才能做到这一点?

请看演示。我建议您将绑定分为两部分—将聚焦行绑定到ViewModel的属性。 然后,将双击操作绑定到
Show
命令:

var fluentAPI = mvvmContext.OfType<MyViewModel>();
// Synchronize the ViewModel.SelectedEntity and the GridView.FocusedRowRandle in two-way manner
fluentAPI.WithEvent<ColumnView, FocusedRowObjectChangedEventArgs>(gridView, "FocusedRowObjectChanged")
    .SetBinding(x => x.SelectedEntity,
        args => args.Row as Student,
            (gView, entity) => gView.FocusedRowHandle = gView.FindRow(entity));
// Proceed the Show command when row double-clicked
fluentAPI.WithEvent<RowClickEventArgs>(gridView, "RowClick").EventToCommand(
        x => x.Show(default(Student)),
            x => x.SelectedEntity,
                args => (args.Clicks == 2) && (args.Button == MouseButtons.Left));

我已经像您一样完成了所有操作,但是visual studio对SelectedEntity(在您的代码中-{SetBinding(x=>x.SelectedEntity})有问题。错误是:“ColumnView”不包含“SelectedEntity”的定义,并且找不到接受“ColumnView”类型的第一个参数的扩展方法“SelectedEntity”(是否缺少using指令或程序集引用?)
var fluentAPI = mvvmContext.OfType<MyViewModel>();
// Synchronize the ViewModel.SelectedEntity and the GridView.FocusedRowRandle in two-way manner
fluentAPI.WithEvent<ColumnView, FocusedRowObjectChangedEventArgs>(gridView, "FocusedRowObjectChanged")
    .SetBinding(x => x.SelectedEntity,
        args => args.Row as Student,
            (gView, entity) => gView.FocusedRowHandle = gView.FindRow(entity));
// Proceed the Show command when row double-clicked
fluentAPI.WithEvent<RowClickEventArgs>(gridView, "RowClick").EventToCommand(
        x => x.Show(default(Student)),
            x => x.SelectedEntity,
                args => (args.Clicks == 2) && (args.Button == MouseButtons.Left));
public class MyViewModel{
    public virtual Student SelectedEntity { 
        get;
        set;
    }
    protected void OnSelectedEntityChanged(){
        this.RaiseCanExacuteChanged(x => x.Show(default(Student)));
    }
    public void Show(Student student){
        //...
    }
}