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

DataTemplate Reuse Problem

1 Answer 168 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 1
Iron
Veteran
Anthony asked on 01 Dec 2016, 01:26 AM

Hi,

I am using a DataTemplateSelector and DataTemplates to show and interact with Custom Appointments in the schedule.

The Custom Appointment has a field called BindingItem added which holds a reference to my data.I then have checkboxes and drop down boxes that bind to fields within the BindingItem.

Everything works great until I refresh the entire appointments collection.

It seems like DataTemplates are being reused (by the container?) and any interaction seems to be with the old BindingItem not the new one, even though the appointment collection is brand new and each appointment has a new BindingItem set.

I can get this resolved in 2 ways, the first is to scroll the offending appointments off the screen and back again which must be forcing some kind of container refresh. Not very useful for end users.

The second is to use the following code to force a container refresh, note that AddIdleAction adds the code onto the dispatcher at application idle priority:

        private void RefreshAppointmentBindingItem(CustomAppointment appt)
        {
            if (appt != null)
            {
                object item = appt.BindingItem;

                AddIdleAction(() =>
                {
                    appt.BindingItem = null;
                });

                AddIdleAction(() =>
                {
                    appt.BindingItem = item;
                });
            }
        }

Both ways are messy, do you have any better suggestions?

Thanks

Anthony

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 05 Dec 2016, 12:16 PM
Hi Anthony

I tried to replicate the reported behavior locally, but to no avail. Can you please take a look at the sample application that I prepared for testing? You should be able to see, that if you click the ModifyItem Button and then the RefreshData one, the control is working with the newly created data. Does the setup demonstrated in the demo project correspond to the one at your end? If not, can you please shed some light in what manner do they differentiate?

Regards,
Stefan X1
Telerik by Progress
Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
Tags
ScheduleView
Asked by
Anthony
Top achievements
Rank 1
Iron
Veteran
Answers by
Stefan
Telerik team
Share this question
or