3 Answers, 1 is accepted
0
Hello Devid,
The desired behavior can be achieved by creating a custom KeyboardCommandProvider and overriding it's ProvideCommandsForKey like so:
Please let me know if this works for you.
Regards,
Dilyan Traykov
Telerik by Progress
The desired behavior can be achieved by creating a custom KeyboardCommandProvider and overriding it's ProvideCommandsForKey like so:
public
override
IEnumerable<ICommand> ProvideCommandsForKey(Key key)
{
List<ICommand> commandsToExecute =
base
.ProvideCommandsForKey(key).ToList();
if
(key == Key.Escape)
{
commandsToExecute.Clear();
parentGrid.SelectedItems.Clear();
}
return
commandsToExecute;
}
Please let me know if this works for you.
Regards,
Dilyan Traykov
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
0
Devid
Top achievements
Rank 1
answered on 24 Jan 2017, 09:38 AM
Thank you. I added a event KeyDown to my RadGridView and implemented it like this and it works:
private
void
GlobalUiRadGridView_OnKeyDown(
object
sender, KeyEventArgs e)
{
if
(Keyboard.IsKeyDown(Key.Escape))
{
this
.MyRadGridView.KeyboardCommandProvider =
new
EscapeCustomKeyboardCommandProvider(
this
.MyRadGridView);
}
}
0
Accepted
Hello Devid,
Rather than set RadGridView's KeyboardCommandProvider each time the Escape key is pressed, I would suggest you set that only once in the window's constructor as suggested in the article I referenced. You may also do that in RadGridView's Loaded event.
I hope you find this suggestion helpful.
Regards,
Dilyan Traykov
Telerik by Progress
Rather than set RadGridView's KeyboardCommandProvider each time the Escape key is pressed, I would suggest you set that only once in the window's constructor as suggested in the article I referenced. You may also do that in RadGridView's Loaded event.
public
MainWindow()
{
InitializeComponent();
this
.MyRadGridView.KeyboardCommandProvider =
new
EscapeCustomKeyboardCommandProvider(
this
.MyRadGridView);
}
public
class
EscapeCustomKeyboardCommandProvider : DefaultKeyboardCommandProvider
{
private
GridViewDataControl parentGrid;
public
EscapeCustomKeyboardCommandProvider(GridViewDataControl grid)
:
base
(grid)
{
this
.parentGrid = grid;
}
public
override
IEnumerable<ICommand> ProvideCommandsForKey(Key key)
{
List<ICommand> commandsToExecute =
base
.ProvideCommandsForKey(key).ToList();
if
(key == Key.Escape)
{
commandsToExecute.Clear();
parentGrid.SelectedItems.Clear();
}
return
commandsToExecute;
}
}
I hope you find this suggestion helpful.
Regards,
Dilyan Traykov
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.