这已经被问过几次不同的变化,但我无法让它们中的任何一个工作。
当在我的视图中单击复选框(在 datagridTemplateColumn.cellTemplate 中)时,我试图在我的视图模型中调用一个方法
<DataGrid ItemsSource="{Binding TransactionTypes}" AutoGenerateColumns="False" CanUserAddRows="False" x:Name="TransTypesGrid">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Command="{Binding DataContext.UpdateCommand, ElementName=TransTypesGrid}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Transaction Type" Binding="{Binding TransTypeDesc}" />
</DataGrid.Columns>
在我的视图模型中
public DelegateCommand UpdateCommand { get; set; }
public myConstructor()
{
this.UpdateCommand = new DelegateCommand(Update);
}
private void Update()
{
//this stuff works, it's just not getting called when a checkbox get's (un)checked
//stuff that goes though the DataGrid's item source's IsSelected property
}