1
votes

Scenario: I have a DataGrid(only 1 Column) in my View. I have applied RowValidationRule on DataGrid in XAML. Whenever user leave a DataGridCell blank, my validation rule fires an error and user can see the red boundary around the row and a tooltip explaining the error. The DataGrid's default behavior doesn't allow user to change any other cell until user fix this current invalid cell. But if user click on Invalid Cell and presses Escape Key the red error message goes away and user can change any other record. What escape key does is it places the last valid value in to the cell.

I am creating column using this XAML

 <DataGridTemplateColumn>
    <DataGridTemplateColumn.CellTemplate>
          <DataTemplate>
              <TextBlock Text="{Binding Path=Type, UpdateSourceTrigger=PropertyChanged}"/>
          </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>

    <DataGridTemplateColumn.CellEditingTemplate>
         <DataTemplate>
              <TextBox Text="{Binding Type, UpdateSourceTrigger=PropertyChanged}"/>
         </DataTemplate>
     </DataGridTemplateColumn.CellEditingTemplate>
 </DataGridTemplateColumn>

Problem: When user presses Escape key on the invalid cell, the cell become valid(using previous value) but the previous value never appears until the user click the previously invalid cell i.e. until the cell style changes to Textbox. In other words the TextBlock never shows the previous value if user presses Escape key and restore the previous value until user again click the cell and tries to edit the value.

So is there any way I can force Textblock to show the value after escape key is pressed without first going in to the Textbox mode?

if above thing is not possible, is there any way that I can stop the Escape key behavior? so that user can't edit any other row until the invalid row is fixed..

1

1 Answers

1
votes

I changed the UpdateSourceTrigger to explicit and it solved the issue

     <DataTemplate>
          <TextBox Text="{Binding Type, UpdateSourceTrigger=Explicit}"/>
     </DataTemplate>