This is a migrated thread and some comments may be shown as answers.

Appointment not updated in GUI if data modified on another thread?

1 Answer 37 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Håkan
Top achievements
Rank 1
Håkan asked on 24 May 2013, 07:36 AM
Hi!

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








1 Answer, 1 is accepted

Sort by
0
Accepted
Yana
Telerik team
answered on 29 May 2013, 09:46 AM
Hi Håkan,

When you edit properties of an appointment with code, it is expected that the changes are not immediately reflected in the UI - we've implemented it like this due to performance optimizations. If you change the ViewDefinition, you will notice that the appointment is updated.

In order to achieve the needed approach, you should use BeginEdit() and Commit() methods of the ScheduleView control, please see the Edit Appointment article for a concrete example.

I hope this helps.

Regards,
Yana
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ScheduleView
Asked by
Håkan
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or