I can't get the binding to a WPF DatePicker work as expected with ReactiveUI. The binding is set up in code like this:
this.Bind(this.ViewModel, x => x.MyDate, x => x.DPMyDate.SelectedDate, DPMyDate.Events().LostKeyboardFocus).DisposeWith(disposables);
In the XAML file it looks like this:
<DatePicker Name="DPMyDate"></DatePicker>
and the bound property is this:
private DateTime myDate;
public DateTime MyDate
{
get { return myDate; }
set
{
this.RaiseAndSetIfChanged(ref myDate, value);
}
}
Changing the date via the calendar works as expected. When I change the date with the keyboard, however, the bound property gets not changed! Interestingly when I move the focus out of the DatePicker after I changed the date, then back in and back out again (without changing anything) the original change gets set. I guess it has something to do with the internal focus handling of the DatePicker with its TextBox but I don't understand whether it's and issue with WPF or ReactivUI.
Any idea?
Update 1
As a test I assigned a handler to the DatePickers LostKeyboardFocus event directly. This event seems to fire everytime the control looses focus. ReactiveUI, however, doesn't pick up the first focus loss!