Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF MVVM textbox text binding vs changedText event

I have textbox with Text property binded to viewmodel. I have binded TextChanged event to viewmodel.

But the problem is that the event fires every sign is added to textbox(that's good) and Text in viewmodel is refreshed when textbox lost focus(that's bad for me).

How to make this Text property refreshing after each sign?

Or how to send sender as parameter? I think sender would have resfreshed data.

My interactivity xaml:

<interactivity:Interaction.Triggers>
    <interactivity:EventTrigger EventName="TextChanged">
        <helpers:CustomCommandInvoker Command="{Binding UnlockChangedCommand}"   />
     </interactivity:EventTrigger>
 </interactivity:Interaction.Triggers>

I'm using RelayCommand.

like image 677
user1736332 Avatar asked Nov 20 '13 07:11

user1736332


1 Answers

There is a really simple answer to this; use UpdatePropertyTrigger=PropertyChanged. This will update your VM property each time a character is changed. No need for triggers or commands :-)

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

Read here for more info: http://msdn.microsoft.com/en-us/library/system.windows.data.updatesourcetrigger(v=vs.110).aspx

like image 136
Espen Medbø Avatar answered Nov 17 '22 05:11

Espen Medbø