Hi!
I have a custom AppointmentItemTemplate that looks like this:
As you can see I also have my own custom derived Appointment called TimeScheduleShift with some extended properties, in this example DayNumber and NbrOfWeeks is used.
In this template they will be displayed as for example 3/2 which means this appointment is day 3 in the second week of a repetative schedule.
When I add a new appointment I need to do a service call to the server to calculate DayNumber and NbrOfWeeks.
So, first the appointment is added to the Appointments collection in the ViewModel, then I make the service call.
That code looks like this:
I need to make a Dispatcher.BeginInvoke() call to avoid cross thread error here, since the SetDayNumberFromTemplate() method will update DayNumber and NbrOfWeeks on the appointment that in turn will raise the PropertyChanged event for those two properties.
Everything works fine and the appointment gets updated with the correct DayNumber and NbrOfWeeks values but it's not updated in the GUI. There it will keep it's default values 0/0 that was assigned before the service call.
Strangely, the tooltip as you can see in the template abowe has the same bindings, and that shows the corrcet numbers.
I guess that the tooltip will be evaluated on mouseover and therfore it is correct?
Do you have any idea why the GUI is not updated. Is it because of the WCF service call or the Dispatcher.BeginInvoke?
Is there any workaround I can do, some refresh or rebinding?
Regards,
Håkan
I have a custom AppointmentItemTemplate that looks like this:
<
DataTemplate
x:Key
=
"CustomAppointmentItemTemplate"
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"14"
/>
<
RowDefinition
Height
=
"14"
/>
</
Grid.RowDefinitions
>
<
TextBlock
Grid.Row
=
"0"
Text
=
"{Binding Subject}"
Margin
=
"0,-1,0,0"
/>
<
Grid
Grid.Row
=
"1"
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"*"
/>
<
ColumnDefinition
Width
=
"Auto"
/>
</
Grid.ColumnDefinitions
>
<
TextBlock
Grid.Column
=
"0"
Text
=
"{Binding Appointment.Location}"
/>
<
StackPanel
Grid.Column
=
"1"
Orientation
=
"Horizontal"
HorizontalAlignment
=
"Right"
Visibility
=
"{Binding Appointment.NbrOfWeeks, Converter={StaticResource NumberToVisibilityConverter}}"
>
<
TextBlock
Text
=
"{Binding Appointment.DayNumber, Converter={StaticResource DayNumberToWeekNumberConverter}}"
/>
<
TextBlock
Text
=
"/"
/>
<
TextBlock
Text
=
"{Binding Appointment.NbrOfWeeks, Converter={StaticResource NbrOfWeeksConverter}}"
/>
</
StackPanel
>
</
Grid
>
<
ToolTipService.ToolTip
>
<
ToolTip
Style
=
"{StaticResource MultiLine_ToolTip}"
>
<
StackPanel
Orientation
=
"Vertical"
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
TextBlock
Text
=
"{Binding Subject}"
/>
<
StackPanel
Orientation
=
"Horizontal"
Margin
=
"5,0,0,0"
Visibility
=
"{Binding Appointment.NbrOfWeeks, Converter={StaticResource NumberToVisibilityConverter}}"
>
<
TextBlock
Text
=
"{Binding Appointment.DayNumber, Converter={StaticResource DayNumberToWeekNumberConverter}}"
/>
<
TextBlock
Text
=
"/"
/>
<
TextBlock
Text
=
"{Binding Appointment.NbrOfWeeks, Converter={StaticResource NbrOfWeeksConverter}}"
/>
</
StackPanel
>
</
StackPanel
>
<
TextBlock
Text
=
"{Binding Appointment.Location}"
/>
</
StackPanel
>
</
ToolTip
>
</
ToolTipService.ToolTip
>
</
Grid
>
</
DataTemplate
>
As you can see I also have my own custom derived Appointment called TimeScheduleShift with some extended properties, in this example DayNumber and NbrOfWeeks is used.
In this template they will be displayed as for example 3/2 which means this appointment is day 3 in the second week of a repetative schedule.
When I add a new appointment I need to do a service call to the server to calculate DayNumber and NbrOfWeeks.
So, first the appointment is added to the Appointments collection in the ViewModel, then I make the service call.
That code looks like this:
private
void
SetDayNumber(TimeScheduleShift shift)
{
var channel = ServiceUtility.GetNewTimeChannel();
channel.BeginGetTimeScheduleTemplate(shift.EmployeeId, shift.Start.Date, (cb) =>
{
TimeScheduleTemplateDTO template = channel.EndGetTimeScheduleTemplate(cb);
Dispatcher.BeginInvoke(() =>
{
SetDayNumberFromTemplate(shift, template);
});
},
null
);
}
I need to make a Dispatcher.BeginInvoke() call to avoid cross thread error here, since the SetDayNumberFromTemplate() method will update DayNumber and NbrOfWeeks on the appointment that in turn will raise the PropertyChanged event for those two properties.
Everything works fine and the appointment gets updated with the correct DayNumber and NbrOfWeeks values but it's not updated in the GUI. There it will keep it's default values 0/0 that was assigned before the service call.
Strangely, the tooltip as you can see in the template abowe has the same bindings, and that shows the corrcet numbers.
I guess that the tooltip will be evaluated on mouseover and therfore it is correct?
Do you have any idea why the GUI is not updated. Is it because of the WCF service call or the Dispatcher.BeginInvoke?
Is there any workaround I can do, some refresh or rebinding?
Regards,
Håkan