天天看點

wpf textblock 接收enter事件 并綁定command

<TextBox Text="{Binding FieldThatIAmBindingToo, UpdateSourceTrigger=PropertyChanged}">

    <TextBox.InputBindings>

        <KeyBinding Command="{Binding AddCommand}" Key="Return" />

    </TextBox.InputBindings>

</TextBox>

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...