【Silverlight】以MVVM友好的方式使用DataGrid的SelectedItems属性

 今天遇到了这样一个问题,通过多选DataGrid中的列,然后批量删除或更新。但是,Silverlight里DataGrid控件的SelectedItems属性无法以MVVM的方式绑定,因为它是个只读属性。

后来想到无非是传递到ViewModel中,用CommandParameter传递不就好了。

XAML:

<Button Content="删除"Margin="4" Command="{Binding DeleteCommand}"

                        CommandParameter="{Binding SelectedItems,ElementName=MyGrid}"/>

 C#:

public IActionCommand<object> DeleteCommand { get; set; }

DeleteCommand = new ActionCommand<object>(Delete);



void Delete(object rows)

{

      var entities = rows as System.Collections.IEnumerable;

       //todo ...

}

我使用的MVVM框架是Jounce

你可能感兴趣的:(silverlight)