Hi,
I'm using ScheduleView to load custom appointments with the Load on demand features. The appointments load fine, but whenever I scroll backward or forward in time (e.g. previous/next week or month) the calendar scrolls back to the top, instead of staying at the time it was scrolled to before navigation.
This also occurs in the RadControls demo; just navigate to Controls -> Data -> Schedule View -> Features -> Load On Demand. Now click Week view. Scroll down to 18:00. Now click the right arrow to navigate to next week. The view scrolls back to the top at 0:00.
Any ideas on how to fix this? I found no method to manually get and set the scrolling position either.
6 Answers, 1 is accepted
The described behavior is causes by the Clear() method of the appointment's collection. When the AppointmentsSource collection is reset the scheduleview regenerates its item and that is why the scroll position is lost.To solve the issue I suggest you avoid the Clear method() and add the new items in a different way.
For example:
private void GenerateAppointments(DateSpan dateSpan)
{
var oldItems = this.Appointments.ToList();
this.Appointments.AddRange(
from i in Enumerable.Range(0, (dateSpan.End - dateSpan.Start).Days * 24)
select new Appointment()
{
Subject = "Appointment" + i + " " + dateSpan.Start.AddHours(i).ToShortDateString(),
Start = dateSpan.Start.AddHours(i),
End = dateSpan.Start.AddHours(i + 1),
});
this.Appointments.Remove(item=>oldItems.Contains(item));
}
}
Regards,
Rosi
the Telerik team
Hi Rosi,
I tried commenting the Clear() call but the calender still resets the view.
Here's a sample of my code:
/// <summary>
/// Gets or sets the afspraken collection
/// </summary>
public
ObservableCollection<Appointment> Afspraken
{
get
{
return
( ObservableCollection<Appointment> )GetValue( AfsprakenProperty );
}
set
{
SetValue( AfsprakenProperty, value );
}
}
/// <summary>
/// Using a DependencyProperty as the backing store for Afspraken. This enables animation, styling, binding, etc...
/// </summary>
public
static
readonly
DependencyProperty AfsprakenProperty =
DependencyProperty.Register(
"Afspraken"
,
typeof
( ObservableCollection<Appointment> ),
typeof
( AgendaView ),
new
UIPropertyMetadata(
new
ObservableCollection<Appointment>() ) );
Binding in XAML:
<
telerik:RadScheduleView
AppointmentsSource
=
"{Binding ElementName=agendaView, Path=Afspraken}"
/>
And I'm adding appointments by directly adding Appointments to the Afspraken observable collection:
//Afspraken.Clear();
foreach
( AfspraakSummary summary
in
result )
{
// maps AfspraakSummary to Appointment
Appointment appointment =
new
Appointment()
{
Body = summary.KorteOpmerking,
Subject = summary.DisplayName,
Start = summary.DatumStartAfspraak.Value,
End = summary.DatumEindeAfspraak.Value,
};
Afspraken.Add( appointment );
}
Note that I use my own appointment (AfspraakSummary) object and map it to a telerik Appointment
Please find the attached project that works as expected at our side.
I suggest you review it and find the differences at your side.You can modify is so the problem to appear and send it back to us to test it locally.
Kind regards,
Rosi
the Telerik team
Perhaps I've not been specific enough about the issue. I linked some screenshots of your attached project to see what it looks like on my computer and what behavior I expect.
http://img685.imageshack.us/img685/3174/telerik1.png
http://img508.imageshack.us/img508/8089/telerik2.png
http://img849.imageshack.us/img849/955/telerik3.png
http://img26.imageshack.us/img26/9562/telerik4.png
Screenshot 1 shows the application's default state when I run it.
Screenshot 2 is when I scrolled down to the last day of the week.
Screenshot 3 shows what happened when I clicked the Next week button at the top right. Notice the view has been scrolled to the top and not fully showing the last day of the week.
Screenshot 4 shows the behavior I expected (view stays in current scrolling position and not resetting)
This scrolling behavior becomes more apparent when I zoom in more (higher ActiveViewDefinition.MinTimeRulerExtent)
Thank you for the provided images. I understand the problem now. However when the current view is changed the days and resource groups of RadScheduleView are recreated.That is why the scroll position is lost. You can use the ScrollIntoView() method to set the scroll position to specific DateTime or Appointment when the view is changed. You can hook on the VisibleRangeChanged event and call the method there.
Hope this helps.
Kind regards,
Rosi
the Telerik team