How can I show my ViewModel that the user is changing text in a TextBox?

So, let's say I have an MVVM application , and I want the user to populate the TextBox, and while he is filling it , I want to check if he has typed the client’s last name .

Here's how I can get ViewModel to know when a user changed an item in a ComboBox :

<ComboBox 
    ItemsSource="{Binding Customers}"
    ItemTemplate="{StaticResource CustomerComboBoxTemplate}"
    Margin="20"
    HorizontalAlignment="Left"
    SelectedItem="{Binding SelectedCustomer, Mode=TwoWay}"/>

And here is how I can get the ViewModel to know when the user moves the slider :

<Slider Minimum="0" 
        Margin="10"
        Width="400"
        IsSnapToTickEnabled="True"
        Maximum="{Binding HighestCustomerIndex, Mode=TwoWay}" 
        Value="{Binding SelectedCustomerIndex, Mode=TwoWay}"/>

And here is how I can get the ViewModel to know when the user has the changed text in the TextBox and removed the focus from the TextBox:

<TextBox
    Width="200"
    Text="{Binding TypedCustomerName}"/>

ViewModel, , TextBox, , . - :

PSEUDO-CODE ( , TextChanged ):

<TextBox
    Width="200"
    TextChanged="{Binding CurrentTextInTextBox}"/>
+3
2

, ViewModel, TextBox , . UpdateSourceTrigger Text binding TextBox LostFocus PropertyChanged, , . , TypedCustomerName VM M .

<TextBox
Width="200"
Text="{Binding TypedCustomerName, UpdateSourceTrigger=PropertyChanged}"/>

, , AttachedCommandBehaviors TextChanged ICommand, .

+10

TextBoxex LostFocus. UpdateSourceTrigger = "PropertyChanged" .

+1

Source: https://habr.com/ru/post/1710773/


All Articles