Caliburn.Micro icon indicating copy to clipboard operation
Caliburn.Micro copied to clipboard

Action Parameter for DatePicker sends previous (old) SelectedDate value

Open Loebe123 opened this issue 11 years ago • 5 comments

When specifying an action parameter for a date picker like follows <DatePicker x:Name ="FromDatePicker" cal:Message.Attach="LoadList($this, $source)"/> the first parameter passed to LoadList will be the previously selected date value. The second paramater (the whole DatePicker UI component object) has the correct SelectedDate set to the new selected date. Unfortunatly passing the whole UI object breaks the internal usage of LoadList in my view model. Workaround is an adapter method, receiving $source, extracting the correct SelectedDate and passing it on to the real LoadList method. Works, but imho isn't really fine.

The following screenshot shows what happens when the 22nd was selected and I select the 24th unbenannt

Loebe123 avatar Aug 19 '14 19:08 Loebe123

I'm assuming this is Windows 8 or Windows Phone 8.1?

Since you're passing sender, can you cast that to the DatePicker and check the Date property on that.

I'm wondering it the event that triggers the action fires too early for that control?

nigel-sampson avatar Aug 20 '14 01:08 nigel-sampson

Ah, yes, this is Windows 8 and WPF. Caliburn Micro 2.0 .net 4.0 (+async bcl) The cast DatePicker has set its Date property (as well as SelectedDate and ShownDate) correctly to the new selected value. You can see this on the bottom of the screenshot under "locales" (sorry its collapsed, but the corresponding value is visible). "sender" ($source) is the DatePicker and has set the 24th (new selected date) while "dateTime" ($this) is the 22nd (previous selected date). The event triggering the action is SelectedDateChanged. That is the default event defined by caliburn.mirco mapped in the ConventionManager. https://github.com/Caliburn-Micro/Caliburn.Micro/blob/master/src/Caliburn.Micro.Platform/ConventionManager.cs Is that event to early? And is it the intended use case? Shouldn't be $this the NEW selected date as is the date value in $source? Because this is the one to be processed by the view model.

Loebe123 avatar Aug 20 '14 17:08 Loebe123

You're right, that all looks good.

Are you seeing this behavior on both WPF and WIndows 8?

nigel-sampson avatar Aug 20 '14 22:08 nigel-sampson

I see it in WPF. Can't tell, if its the same for Windows 8.

Loebe123 avatar Aug 21 '14 13:08 Loebe123

I've managed to replicate the issue, internally Calburn.Micro turns cm:Message.Attach="LoadList($this)" into an ActionMessage that looks like.

<DatePicker x:Name="ListDate">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectedDateChanged">
            <cal:ActionMessage MethodName="LoadList">
                <cal:Parameter Value="{Binding ElementName=ListDate, Path=SelectedDate, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>
            </cal:ActionMessage>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</DatePicker>

There appears to be timing issue where the Parameter binding hasn't updated when the SelectedDateChanged event fires so the wrong value is passed to the method. This could depend on the internals of the WPF DatePicker control. Still looking into it.

nigel-sampson avatar Aug 22 '14 04:08 nigel-sampson