我有一个命令按钮定义为:
<r:RibbonButton Command = "{StaticResource cmdRemoveCustomer}" Label="Remove Customer"
CommandParameter="{Binding}" DataContext="{Binding ElementName=dataGridCustomers,
Path=SelectedItems}" />
和一个数据网格
<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;
}
我尝试直接从数据网格中删除项目,但收到一条错误消息,指出我应该从 ItemsSource 中删除项目。数据网格通过代码绑定到一个 observablecollection。
dataGridTrackCustomers.ItemsSource = Customers;
如何使用 RibbonRemoveCustomer 命令从客户对象中删除数据网格中的所有选定客户?