0
DataGrid中删除选定的项目我有一个命令按钮定义为:如何绑定到一个对象
<r:RibbonButton Command = "{StaticResource cmdRemoveCustomer}" Label="Remove Customer"
CommandParameter="{Binding}" DataContext="{Binding ElementName=dataGridCustomers,
Path=SelectedItems}" />
而且一个DataGrid
<DataGrid AutoGenerateColumns="False" Height="394" HorizontalAlignment="Left"
x:Name="dataGridCustomers" VerticalAlignment="Top" Width="803" >
<DataGrid.Columns>
现在我想删除所选项目
public class RibbonRemoveCustomer : ICommand
{
public void Execute(object parameter)
{
// ??? How to remove selected customers?
}
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
}
我试着直接从数据网格中删除项目,但得到一个错误,指出我应该从ItemsSou中删除项目RCE。 datagrid通过代码绑定到observablecollection。
dataGridTrackCustomers.ItemsSource = Customers;
如何使用RibbonRemoveCustomer命令从Customers对象中的datagrid中删除所有选定的客户?