1

I've a WPF DataGrid with a DataGridTemplateColumn like this:

<DataGridTemplateColumn IsReadOnly="False">
<DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
        <TextBlock
            Text="{Binding Path=MyProperty, Mode=OneWay}" />
    </DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
    <DataTemplate>
        <TextBox
            Text="{Binding Path=MyProperty, UpdateSourceTrigger=PropertyChanged}"
            TextChanged="ctl_TextChanged" />
    </DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>

I noticed that every time I go into a cell edit, a new textbox control is generated and, consequently, if I start typing a character, the TextChanged event is invoked several times...once for each instance of the control that was generated!

Sample project to reproduce the issue: TestEditingTemplate_4.5.2

I used the TextChanged event only for example, but the issue may also occur with other events (eg. events defined within a UserControl)

Is there is a way to avoid this behavior? I wish to destroy the "edit" control on CellEditEnding, so that it does not interfere with the new control generated when I return to cell edit; how can I do?

Luca Petrini
  • 1,695
  • 2
  • 28
  • 53
  • The TextChanged should only be invoked once for each key press. Your issue is not reproducible. – mm8 Apr 24 '17 at 10:38
  • I've created a simple application with a DataGrid and a DataGridTemplateColumn...the problem is reproducible; if edit same cell 2 times, then at each key press the event is invoked 2 times...and so on (.NET 4.0) – Luca Petrini Apr 24 '17 at 12:42
  • I cannot reproduce it. I am not on .NET 4.0 though but the oldest officially supported version is 4.5.2 so you should probably update. – mm8 Apr 24 '17 at 12:44
  • I tried with 4.5.2, but no change...here there is the sample project: https://1drv.ms/u/s!AjtirGjxfFwZhVw-y-jfge9doVuk – Luca Petrini Apr 24 '17 at 13:20

0 Answers0