Warning -- I am a newb when it comes to WPF. So what I am trying to do is have a textbox that is bound to a string property in my ViewModel. When the user clears the textbox, I want it to automatically go back to what the user had initially (when window opened). Basically I am preventing the user from clearing the textbox.
Currently, my WPF has the binding as TwoWay and and I do have the UpdateSourceTrigger set to PropertyChanged. I think I want to keep that UpdateSourceTrigger because I like the property in my ViewModel to get updated when the user makes one little change. That way I can do other UI stuff when the user does something (ex - update my Save button because the user changed something).
My property in my ViewModel looks like this currently, with me attempting to use the original value:
public string SourceName
{
get { return this.sourceName; }
set
{
if (!this.sourceName.Equals(value, StringComparison.OrdinalIgnoreCase))
{
if (!string.IsNullOrWhiteSpace(value))
this.sourceName = value;
else
this.sourceName = this.configuredSource.Name;
RaisePropertyChanged("SourceName");
}
}
}
The problem I am having is that I think the View is ignoring my 'RaisePropertyChanged' because of the UpdateSourceTrigger I have set. If I take out the trigger, then this works, but I have to lose focus on the control to have the UI update. Hence why I want to keep the trigger if I can.
Anyone have a nice way to revert back to the original value if the user clears the textbox?