I am fairly new to MVVM and wpf. I was implementing a simple login page that connects to the database to retrieve user details. In the view model i have a string field called Error that stores any error like wrong password or connection error to show up on view. I bound the error to a textblock in view. So on pressing the login button if some error happens i update the text of error. But the problem is the change is not reflected in view.
string _error;
public string Error
{
get { return _error; }
set { _error = value; }
}
update the field as
_error = "Wrong password!";
In the view:
<TextBlock Text="{Binding Error, UpdateSourceTrigger=PropertyChanged}"/>
What is the problem?
Edit: I read article on Code Project and am implementing it in similar way. Still it is not working?
You need to send out a property changed event from the ViewModel. The class needs to implement the
INotifyPropertyChanged
interface that contains the event you need to fire. The parameter of the event needs to be the name of the property you changed.