In response to Mark Heath, I took one step at a time, thus doing the property of the attached Command Parameter;
public static class EnterKeyHelpers { public static ICommand GetEnterKeyCommand(DependencyObject target) { return (ICommand)target.GetValue(EnterKeyCommandProperty); } public static void SetEnterKeyCommand(DependencyObject target, ICommand value) { target.SetValue(EnterKeyCommandProperty, value); } public static readonly DependencyProperty EnterKeyCommandProperty = DependencyProperty.RegisterAttached( "EnterKeyCommand", typeof(ICommand), typeof(EnterKeyHelpers), new PropertyMetadata(null, OnEnterKeyCommandChanged)); public static object GetEnterKeyCommandParam(DependencyObject target) { return (object)target.GetValue(EnterKeyCommandParamProperty); } public static void SetEnterKeyCommandParam(DependencyObject target, object value) { target.SetValue(EnterKeyCommandParamProperty, value); } public static readonly DependencyProperty EnterKeyCommandParamProperty = DependencyProperty.RegisterAttached( "EnterKeyCommandParam", typeof(object), typeof(EnterKeyHelpers), new PropertyMetadata(null)); static void OnEnterKeyCommandChanged(DependencyObject target, DependencyPropertyChangedEventArgs e) { ICommand command = (ICommand)e.NewValue; Control control = (Control)target; control.KeyDown += (s, args) => { if (args.Key == Key.Enter) {
Using:
<TextBox Text="{Binding Answer, Mode=TwoWay}" my:EnterKeyHelpers.EnterKeyCommand="{Binding SubmitAnswerCommand}" my:EnterKeyHelpers.EnterKeyCommandParam="your parameter"/>
TY Kucuk Sep 21 '15 at 21:32 2015-09-21 21:32
source share