I know this is 6 years old, but none of the answers give the correct answer in full using XAML and without code. I still had to do something. For reference, the approach is as follows. Xaml first
<TextBox Text="{Binding SearchText, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"> <TextBox.InputBindings> <KeyBinding Key="Enter" Command="{Binding SearchEnterHit}"/> <KeyBinding Key="Return" Command="{Binding SearchEnterHit}"/> </TextBox.InputBindings> </TextBox>
Basically, the approach is that each key is thrown into the associated SearchText each time a key is pressed. Thus, the string will be fully present in SearchText after pressing the return / enter button. Thus, in the SearchEnterHit command, the entire line in the TextBox is accessible through the SearchText property.
As mentioned above, UpdateSourceTrigger = PropertyChanged is what resets each keystroke to the SearchText property. KeyBindings captures an input key.
This is indeed the easiest way to do this without code and all of XAML. I am sure that you often blush the keys to the SearchText property, but this is not a problem at all.
sagneta Aug 30 '17 at 13:00 2017-08-30 13:00
source share