开发者

How to Implement the ICommand as DependencyProperty

开发者 https://www.devze.com 2023-03-04 10:08 出处:网络
I am using the implementation give at Bind TextBox on Enter-key press to handle the enter key for text box.

I am using the implementation give at Bind TextBox on Enter-key press to handle the enter key for text box.

But I am using MVVm pattern for my application. Therefore I have defi开发者_StackOverflowned the ICommand handler in my VieModel class. I want to bind it to view.

The sample application uses

InputBindingsManager.UpdatePropertySourceWhenEnterPressed="TextBox.Text" 

and I want to use

InputBindingsManager.UpdatePropertySourceWhenEnterPressed="{Binding myCommandHandler}"

instead.

Can anybody suggest what modification are required in the code?


You can go for inputbindings for a textbox. in this you can bind a Icommand object to command property ok keybindings

Here is the sample code

<TextBox Text="{Binding Firstname, UpdateSourceTrigger=PropertyChanged}">
                        <TextBox.InputBindings>
                            <KeyBinding Key="Enter" Command="{Binding ValidationCommand}">
 </KeyBinding>
                        </TextBox.InputBindings>
                    </TextBox>
0

精彩评论

暂无评论...
验证码 换一张
取 消