RayOldProf RayOldProf - 4 years ago 134
C# Question

Wpf TextBox databinding update

I have a TextBox and it is binded to a string property:


<TextBox x:Name="SearchBox"
Text="{Binding SearchText, Source={StaticResource SearchEngine}, Mode=TwoWay}"

and the class which is binded to:

public class SearchEngine : ViewModelBase
private string _searchText = string.Empty;

public SearchEngine() {
Console.Out.WriteLine("this = {0}", this);
SearchText = "Search";

public string SearchText
get { return _searchText; }
if (_searchText != value)
_searchText = value;
Console.Out.WriteLine("AAAAAAAAAAAA: " + value);

The problem is that when I type in the TextBox, the
doesn't get updated.

Answer Source

You have to use the updatesourcetrigger in your xaml like:

<TextBox x:Name="SearchBox" Text="{Binding SearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged"/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download