How to set the binding.UpdateSourceTrigger of DataGridTextColumn in AutoGeneratingColumn event of DataGrid

时间:2017-10-30 15:34:05

标签: c# wpf datagrid

I would like to set the UpdateSourceTrigger of a DataGridTextColumn binding to "LostFocus" from the code-behind in the AutoGeneratingColumn event. The default behavior is that the source is only updated when the row loses focus, but I need it to update when the cell loses focus.

Here is my attempt:

    private void DataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
    {
            //my attempt to get cell to update on cell lost-focus, rather than row lost-focus
            Binding newBinding = new Binding(e.PropertyName);
            newBinding.UpdateSourceTrigger = UpdateSourceTrigger.LostFocus;
            (e.Column as DataGridTextColumn).Binding = newBinding;
    }

This does not seem to be working because the source is still only being updated once the row loses focus.

Note: I am aware this is usually done in the XAML in the column defintion, but I cannot put it there because my columns are being dynamically generated at run-time.

0 个答案:

没有答案