Here's my problem, when application starts up then user selects textbox. Without typing anything user clicks tab to select next textbox. This should trigger the setter method in viewmodel for the first textbox binding. But it seems not to happen.
In viewmodel:
private string _username;
public string Username
{
get { return _username; }
set
{
_username = value;
RaisePropertyChanged("Username");
Validator.Validate(() => Username);
}
}
And in xaml:
<TextBox Text="{Binding Username, Mode=TwoWay, ValidatesOnDataErrors=True}" />
Username setter method gets called when i start to type something, then erase it and move focus to something else. Datacontext is properly set and working.
1) User sets focus to Username textbox, does not type anything
2) User moves focus to next item on form
Result = Setter method in view model is not called when Username textbox loses focus
Result i need = Setter method is called even when user does not type anything
TextBox
haven't changed, why would the view model's setter be called? Why not just handle theLostFocus
event if you want to know when the control has lost focus? And why would you want to do a property-changed notification and data validation when the value hasn't actually changed? I find this question very confusing. – Peter DunihoLostFocus
event in the code behind. But when there is many textboxes on the form then i would have to do that for all of them... – hs2d