In a WPF application, I have a control that I have derived from TextBox like this:
public class SelectableTextBlock : TextBox
{
protected override void O
Derive a say, RestrictKeysTextBox from TextBox.
public class RestrictKeysTextBox : TextBox
{
....
}
Override the OnPreviewKeyDown event in the RestrictKeysTextBox.
Put logic in this override like this:
if (e.Key == Key.Space)
{
e.Handled = true;
}
Bind the instance of the RestrictKeysTextBox to your DataGrid.
That should work without overriding the OnPreviewKeyDown in the DataGrid and eliminate the associated problems.