DataGridTemplateColumn的RowEditEnding事件不起作用

本文关键字:不起作用 事件 RowEditEnding DataGridTemplateColumn | 更新日期: 2023-09-27 18:24:39

我有以下wpf网格,当用户更改事件不适用于DataGridTemplateColumn时,我想调用RowEditEnding事件。DataGridTemplateColumn仅在我更改datagrid定义的控件(如DataGridTextColumnDataGridComboBoxColumn等)中的值时执行

   <DataGrid Name="DriversDataGrid" Width="360" ItemsSource="{Binding GetAll}" CommandManager.PreviewExecuted="DriversDataGrid_PreviewDeleteCommandHandler" AutoGenerateColumns="False" RowEditEnding="DataGrid_RowEditEnding">
      <DataGrid.Columns>
         <DataGridTemplateColumn Header="Latest Victory Date" >
            <DataGridTemplateColumn.CellTemplate>
              <DataTemplate>
                <DatePicker SelectedDate="{Binding LatestVictory, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" BorderThickness="0></DatePicker>
              </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
         </DataGridTemplateColumn >
     </DataGrid.Columns>
  </DataGrid>

这是我的活动代码

  private void DataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            if (e.EditAction == DataGridEditAction.Commit)
            {
                FormulaOneDriver driver = e.Row.DataContext as FormulaOneDriver;
                MessageBox.Show("test");
                driver.Save();
            }
        }

如何为DataGridTemplateColumn元素中发生变化的数据调用RowEditEnding事件

DataGridTemplateColumn的RowEditEnding事件不起作用

添加CellEditingTemplate。这需要用户点击两次-一次选择单元格,另一次进入单元格编辑模式

            <DataGridTemplateColumn Header="Latest Victory Date" SortMemberPath="LatestVictory">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding LatestVictory, Mode=TwoWay}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
                <DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <DatePicker SelectedDate="{Binding LatestVictory, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ConverterCulture='en-GB', StringFormat=d}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellEditingTemplate>
            </DataGridTemplateColumn>