I have created a errorMessage as a string in my ViewModel. When you get an error or stuff like that, I will use this one to display a message to the user.
In ViewModel
I have implemented the INotifyPropertyChanged interface, also I have created this block:
#region INotifyPropertyChanged members
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
In top of the ViewModel, I have created a string called ErrorMessage.
public string ErrorMessage { get; set; }
In the constructor, I have tested it with
ErrorMessage = "Error message";
And I can see the text in my view on load. The problem is when I hit an exception like in a try / catch block and sets the error to a text, it wont get updated.
In the Exception or on a button click, I have tried entering:
ErrorMessage = "No rooms with entered settings were found";
The View
<StackPanel Margin="10, 5" Grid.Row="5" Grid.ColumnSpan="3">
<TextBlock FontFamily="../Fonts/bold.ttf#bold" Height="40" Foreground="Red" Text="{Binding ErrorMessage, UpdateSourceTrigger=PropertyChanged}"></TextBlock>
</StackPanel>
If you scroll to the right, you can see that I have binded ErrorMessage and given it the UpdateSourceTrigger=PropertyChanged.
What do I need, so I can in my ViewModel, set the ErrorMessage equal to a text on certain scenarios?