حرکت روی سلول های دیتا گرید با فشردن کلید Enter در برنامه های WPF
نویسنده: محبوبه محمدی
تاریخ: ۱۳۹۲/۱۱/۲۳ ۱۳:۳۵
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
public partial class App : Application
{ EventManager.RegisterClassHandler(typeof(TextBox), TextBox.KeyDownEvent, new KeyEventHandler(TextBox_KeyDown));
...
}
private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key != Key.Enter)
return;
var focusedElement = Keyboard.FocusedElement as TextBox;
focusedElement.MoveFocus(new TraversalRequest(FocusNavigationDirection .Next));
} public class CommonDataGrid : DataGrid
{
protected override void OnPreviewKeyDown(KeyEventArgs e)
{
base.OnPreviewKeyDown(e);
if (e.Key != Key.Enter || Keyboard.PrimaryDevice.ActiveSource == null) return;
this.CommitEdit();
var args = new KeyEventArgs
(Keyboard.PrimaryDevice,
Keyboard.PrimaryDevice.ActiveSource, 0, Key.Tab) { RoutedEvent = Keyboard.KeyDownEvent };
InputManager.Current.ProcessInput(args);
}
}