Executing viewmodels command on enter in TextBox

后端 未结 5 1359
深忆病人
深忆病人 2020-12-24 00:23

I want to execute a command in my viewmodel when the user presses enter in a TextBox. The command works when bound to a button.

5条回答
  •  伪装坚强ぢ
    2020-12-24 00:51

    I know I am late to the party, but I got this to work for me. Try using Key="Return" instead of Key="Enter"

    Here is the full example

    
        
            
        
    
    

    Make sure to use UpdateSourceTrigger=PropertyChanged in your binding, otherwise the property will not be updated until focus is lost, and pressing enter will not lose focus...

    Hope this was helpful!

提交回复
热议问题