Invoke Command When “ENTER” Key Is Pressed In XAML

后端 未结 5 442
花落未央
花落未央 2020-12-24 08:38

I want to invoke a command when ENTER is pressed in a TextBox. Consider the following XAML:



        
5条回答
  •  伪装坚强ぢ
    2020-12-24 09:10

    I used scottrudy's code in my application however, my textbox text is bound to some property in viewmodel class and this property is not getting updated by the time command is invoked after pressiong ENTER key because my textbox hasn't lost focus yet. So, to resolved this, i added the following code snippets just above InvokeActions(o) in AssociatedObject_KeyUp method and updated text property is getting updated in viewmodel class.

                        BindingExpression bindingExpression = (textBox).GetBindingExpression(TextBox.TextProperty);
                    bindingExpression.UpdateSource();
    

提交回复
热议问题