The exact exception is this: "Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
The first time I call CreateNew on my ScheduleView, the IAppointment object is created and I'm able to set its properties. But any further attempt to touch the AppointmentsSource seems to result in the above exception. Am I doing something wrong or is this a bug?
MainPage.xaml
MainPage.xaml.cs
GraphTestViewModel.cs
Parameter name: index"
The first time I call CreateNew on my ScheduleView, the IAppointment object is created and I'm able to set its properties. But any further attempt to touch the AppointmentsSource seems to result in the above exception. Am I doing something wrong or is this a bug?
MainPage.xaml
<
UserControl
x:Class
=
"SVIssue.MainPage"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
xmlns:SVIssue
=
"clr-namespace:SVIssue"
mc:Ignorable
=
"d"
d:DesignHeight
=
"300"
d:DesignWidth
=
"400"
>
<
UserControl.Resources
>
<
SVIssue:GraphTestViewModel
x:Key
=
"GraphTestViewModel"
/>
<
telerik:OrientedGroupHeaderStyleSelector
x:Key
=
"GroupHeaderStyleSelector"
>
<
telerik:OrientedGroupHeaderStyleSelector.VerticalBottomLevelStyle
>
<
Style
TargetType
=
"telerik:GroupHeader"
>
<
Style.BasedOn
>
<
Style
TargetType
=
"telerik:GroupHeader"
>
<
Setter
Property
=
"Foreground"
Value
=
"Red"
/>
<
Setter
Property
=
"FontStyle"
Value
=
"Italic"
/>
</
Style
>
</
Style.BasedOn
>
</
Style
>
</
telerik:OrientedGroupHeaderStyleSelector.VerticalBottomLevelStyle
>
</
telerik:OrientedGroupHeaderStyleSelector
>
</
UserControl.Resources
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
/>
</
Grid.RowDefinitions
>
<
Button
x:Name
=
"btnAddData"
Content
=
"Add Data"
HorizontalAlignment
=
"Center"
Click
=
"btnAddData_Click"
/>
<
telerik:RadScheduleView
x:Name
=
"svTest"
Grid.Row
=
"1"
DataContext
=
"{StaticResource GraphTestViewModel}"
AppointmentsSource
=
"{Binding Appointments}"
ResourceTypesSource
=
"{Binding ResourceTypes}"
GroupHeaderStyleSelector
=
"{StaticResource GroupHeaderStyleSelector}"
>
<
telerik:RadScheduleView.ViewDefinitions
>
<
telerik:DayViewDefinition
Orientation
=
"Horizontal"
GroupHeaderDateStringFormat
=
"{}{0:dddd}"
/>
<
telerik:WeekViewDefinition
Orientation
=
"Horizontal"
/>
<
telerik:TimelineViewDefinition
Orientation
=
"Horizontal"
/>
</
telerik:RadScheduleView.ViewDefinitions
>
<
telerik:RadScheduleView.GroupDescriptionsSource
>
<
telerik:GroupDescriptionCollection
>
<
telerik:DateGroupDescription
/>
<
telerik:ResourceGroupDescription
ResourceType
=
"Speaker"
/>
<
telerik:ResourceGroupDescription
ResourceType
=
"Room"
/>
</
telerik:GroupDescriptionCollection
>
</
telerik:RadScheduleView.GroupDescriptionsSource
>
</
telerik:RadScheduleView
>
</
Grid
>
</
UserControl
>
MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.ScheduleView;
namespace SVIssue
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void btnAddData_Click(object sender, RoutedEventArgs e)
{
DateTime currentTime = DateTime.Today.AddHours(1);
int count = 0;
while (currentTime < DateTime.Today.AddDays(1))
{
IAppointment appointment = this.svTest.CreateNew();
appointment.Start = currentTime;
appointment.End = currentTime.AddMinutes(59).AddSeconds(59);
appointment.Subject = String.Format("New appointment {0}", count++);
//appointment.Resources.Add(this.Resources[0].Resources[0]);
currentTime = currentTime.AddHours(1);
}
this.svTest.Commit();
}
}
}
GraphTestViewModel.cs
using System;
using System.Collections.ObjectModel;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.ScheduleView;
namespace SVIssue
{
public class GraphTestViewModel
{
public ObservableCollection<
Appointment
> Appointments { get; set; }
public ObservableCollection<
ResourceType
> ResourceTypes { get; set; }
public GraphTestViewModel()
{
this.Appointments = new ObservableCollection<
Appointment
>();
this.ResourceTypes = this.GenerateResourceTypes();
}
private ObservableCollection<
ResourceType
> GenerateResourceTypes()
{
ObservableCollection<
ResourceType
> newResourceTypes = new ObservableCollection<
ResourceType
>();
ResourceType roomType = new ResourceType("Room");
Resource room102 = new Resource("Room 102");
Resource room203 = new Resource("Room 203");
Resource room406 = new Resource("Room 406");
roomType.Resources.Add(room102);
roomType.Resources.Add(room203);
roomType.Resources.Add(room406);
ResourceType speakerType = new ResourceType("Speaker");
Resource tomSpeaker = new Resource("Tom");
Resource peterSpeaker = new Resource("Peter");
speakerType.Resources.Add(tomSpeaker);
speakerType.Resources.Add(peterSpeaker);
newResourceTypes.Add(roomType);
newResourceTypes.Add(speakerType);
return newResourceTypes;
}
}
}