Hy all.
I have a question about the XamDateTimeEditor control.
I have a simple wpf application with a form for which I set the DataContext to a Controller class.
In this Controller class I have an object that has two properties. The DateTime property (DateValue) it's bounded to the XamDateTimeEditor value and the string property (TextValue) it's bounded to a TextBox control.
I have noticed that every time when the XamDateTimeEditor gets the focus, it will call the set method for the DateValue of the object even if the DateValue was not changed. For the TextBox control it will call the set method of the TextValue property only after losing the focus on the control.
Do you know if I must do something so that the XamDateTimeEditor will not call the set method when it gets the focus? I have also attached a sample.
Thanks a lot.
Nico
I didn't see the setter getting hit when the control first got focus. I think this may be a difference between the versions we are using. I believe at one point there was a bug where the time portion was not getting included in the date when the mask didn't have time portion and since you are initializing the DateValue with DateTime.Now (which includes time) then the value would have been different between the value from the mask when it excluded the time. To address that you may want to get the latest hotfix or if you didn't include the time in the DateValue (e.g. used DateTime.Today). Note I'm speculating as to why you might see the setter get hit initially since I'm not actually seeing that.
With regards to losing focus vs when the value has changed, this comes down to a difference in the way the properties are defined. TextBox's TextProperty is one of the few dependency properties in WPF that is defined such that the DefaultUpdateSourceTrigger is LostFocus. So when you define a binding to the TextBox's Text property and you do not specify the UpdateSourceTrigger on the binding, it uses the DefaultUpdateSourceTrigger of the DP you are binding. In the case of the TextBox's Text property that will be LostFocus and therefore the binding will only push the value back into the source when the control loses logical focus. It is important to understand that this is logical focus and not keyboard focus. So if you lose focus to another window, another application, or even another element in a different focus scope (e.g. a menuitem in a menu, a tool in a ribbon or toolbar), the control still has logical focus and therefore the binding will not push the updated value into the underlying object (your DateTimeBo in this case). If you want to have the same effect with the XamDateTimeEditor then you must set the UpdateSourceTrigger on the Binding to LostFocus. e.g.
Hello Andrew.
Yes, you are right. It's because of the versions. I have the problem in 8.2. I have tried the sample in 9.1 and it's working fine. The setter it's not called when the XamDateTimeEditor get's the focus.
Thanks very much for the suggestion.