看一下Table (CollectionView)演示。我建议您将绑定拆分为两部分 - 将 Focused 行绑定到 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));
视图模型:
public class MyViewModel{
public virtual Student SelectedEntity {
get;
set;
}
protected void OnSelectedEntityChanged(){
this.RaiseCanExacuteChanged(x => x.Show(default(Student)));
}
public void Show(Student student){
//...
}
}