Silverlight MVVM - Twoway binding not fired on Datepicker
I have Silverlight MVVMLight 4.0 application in which I have datepicker.
The datepicker is two way bound to the viewmodel. There is no code behind.
This works fine when tabbing of the datepickers textbox and will change the underlying property of the object.
But when I change the text box and don't tab off and click save the change is no开发者_如何学JAVAt registered.
I have looked at the various events that are fired and they don't fire unless you tab off
private void startDateDatePicker_TextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
{
}
private void startDateDatePicker_TextInputStart(object sender, System.Windows.Input.TextCompositionEventArgs e)
{
}
private void startDateDatePicker_TextInputUpdate(object sender, System.Windows.Input.TextCompositionEventArgs e)
{
}
private void startDateDatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
{
}
Does anybody have a workaround for this?
kind regards,
Pat
I'm fairly sure that the TextBox
needs to lose focus before the property is updated.
You could try handling the KeyDown
event of the TextBox
and update the property from there, but I'm not sure how well that would behave.
Change the UpdateSourceTrigger value in your binding. If is not set, uses the default (which is the Lost Focus for TextBox.Text) Depending the inner-workings and needs of your screen, you can set it to PropertyChanged or Explicit.
http://msdn.microsoft.com/en-us/library/ms752347.aspx
精彩评论