码迷,mamicode.com
首页 > Windows程序 > 详细

WPF Datagrid multiple selecteditems in MVVM

时间:2014-12-23 20:52:48      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:

I can assure you: SelectedItems is indeed bindable as a XAML CommandParameter

After a lot of digging and googling, I have finally found a simple solution to this common issue.

To make it work you must follow ALL the following rules:

  1. Following Ed Ball‘s suggestion‘, on you XAML command databinding, define CommandParameterproperty BEFORE Command property. This a very time-consuming bug.

    技术分享

  2. Make sure your ICommand‘s CanExecute and Execute methods have a parameter of object type. This way you can prevent silenced cast exceptions that occurs whenever databindingCommandParameter type does not match your command method‘s parameter type.

    private bool OnDeleteSelectedItemsCanExecute(object SelectedItems)
    {

       // Your goes heres

    }

    private bool OnDeleteSelectedItemsExecute(object SelectedItems)
    {

       // Your goes heres

    }

For example, you can either send a listview/listbox‘s SelectedItems property to you ICommand methods or the listview/listbox it self. Great, isn‘t it?

Hope it prevents someone spending the huge amount of time I did to figure out how to receiveSelectedItems as CanExecute parameter.

WPF Datagrid multiple selecteditems in MVVM

标签:

原文地址:http://www.cnblogs.com/xpvincent/p/4180804.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!