标签:style http io os ar for div sp cti
单选,很简单,将SelectedItem与ViewModel的属性进行双向绑定就OK了
多选,由于ListView的SelectedItems不能进行绑定,需要将ListView的SelectionChanged事件转换成命令绑定到ViewModel,同时将SelectedItems传递到ViewModel层
示例:
首先添加程序集引用System.Windows.Interactivity.dll
xaml
添加命名空间引用
viewmodel:
public RelayCommand<IList> SelectionChangeCommand
{
get
{
return new RelayCommand<IList>
(
(selectedItems) =>
{
TotalSelectedSales = 0;
CustomerViewModel firstCustomer = null;
if (selectedItems.Count > 0)
firstCustomer = selectedItems[0] as CustomerViewModel;
// 将选中第一条CustomerViewModel传递到主页面
selectedCustomer = firstCustomer;
// 更新按钮的可执行状态
EditCustomerCommand.RaiseCanExecuteChanged();
DeleteCustomerCommand.RaiseCanExecuteChanged();
foreach (dynamic Item in selectedItems)
TotalSelectedSales += Item.TotalSales;
RaisePropertyChanged("TotalSelectedSales");
}
);
}
}
Mvvm绑定datagrid或listview的selectItems的方法[转]
标签:style http io os ar for div sp cti
原文地址:http://www.cnblogs.com/xiangfeideshui/p/3978637.html