This question is locked. New answers and comments are not allowed.
Presently I'm working on RadScheduleView control (Silverlight 4 version)
to display two different type of appointments. Following is scale downversion of what I'm trying to do,
Then my actual container class which represents the appointment in the AppointmentSource is as follows,
Then my AppointmentItemContentTemplate is as follows
AppointmentTypeOneCtrl is
and AppointmentTypeTwoCtrl is
I generate two of each kind in the viewmodel for ScheduleView as follows
Things show fine as expected when the application is lauched. But when I scroll up/down in the Daily view the appointment views which were initially visible just go blank. I was not able figure why this is happening intermittently. This problem can well understood if it is seen live. I would like to post repro project that I created.
Please help me in this problem
Thanks
-Obaid
to display two different type of appointments. Following is scale downversion of what I'm trying to do,
public abstract class AppointmentTypeBase : AppointmentBase { } public class AppointmentTypeOne : AppointmentTypeBase { public override IAppointment Copy() { var appt = new AppointmentTypeOne(); appt.CopyFrom(this); return appt; } } public class AppointmentTypeTwo : AppointmentTypeBase { public override IAppointment Copy() { var appt = new AppointmentTypeTwo(); appt.CopyFrom(this); return appt; } }Then my actual container class which represents the appointment in the AppointmentSource is as follows,
public class AppointmentContainer : AppointmentBase { public override IAppointment Copy() { return this; } public AppointmentTypeBase AppointmentBase { get; set; } public override DateTime Start { get { if (this.AppointmentBase != null) return this.AppointmentBase.Start; return base.Start; } set { if (this.AppointmentBase != null) this.AppointmentBase.Start = value; base.Start = value; } } public override DateTime End { get { if(this.AppointmentBase!=null) return this.AppointmentBase.End; return base.End; } set { if (this.AppointmentBase != null) this.AppointmentBase.End = value; base.End = value; } } public override string Subject { get { if (this.AppointmentBase != null) return this.AppointmentBase.Subject; return base.Subject; } set { if (this.AppointmentBase != null) this.AppointmentBase.Subject = value; base.Subject = value; } } }Then my AppointmentItemContentTemplate is as follows
<DataTemplate x:Key="AppointmentViewTemplate"> <Grid DataContext="{Binding Appointment.AppointmentBase}"> <ContentPresenter Content="{Binding}"> <ContentPresenter.ContentTemplate> <Binding> <Binding.Converter> <local:TypeToTemplateConverter> <local:TypeToTemplateConverter.Resources> <ResourceDictionary> <DataTemplate x:Key="appointmentTypeOne"> <local:AppointmentTypeOneCtrl /> </DataTemplate> <DataTemplate x:Key="appointmentTypeTwo"> <local:AppointmentTypeTwoCtrl /> </DataTemplate> </ResourceDictionary> </local:TypeToTemplateConverter.Resources> </local:TypeToTemplateConverter> </Binding.Converter> </Binding> </ContentPresenter.ContentTemplate> </ContentPresenter> </Grid> </DataTemplate>AppointmentTypeOneCtrl is
<UserControl x:Class="ScheduleViewError.AppointmentTypeOneCtrl" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Rectangle Grid.Row="0" Grid.RowSpan="3" Stroke="{x:Null}"> <Rectangle.Fill> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF0036FF" Offset="0" /> <GradientStop Color="#FF6B86E2" Offset="1" /> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <TextBlock Grid.Row="1" Margin="2" Foreground="White" Text="{Binding Subject}" TextWrapping="Wrap" /> </Grid></UserControl>and AppointmentTypeTwoCtrl is
<UserControl x:Class="ScheduleViewError.AppointmentTypeTwoCtrl" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Rectangle Grid.Row="0" Grid.RowSpan="3" Stroke="{x:Null}"> <Rectangle.Fill> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF4B0348" Offset="0" /> <GradientStop Color="#FFBC5CB9" Offset="1" /> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <TextBlock Grid.Row="1" Margin="2" Foreground="White" Text="{Binding Subject}" TextWrapping="Wrap" /> </Grid></UserControl>
I generate two of each kind in the viewmodel for ScheduleView as follows
public class CalendarViewModel : ViewModelBase { public CalendarViewModel() { if(!IsDesignTime) { VisibleRangeChangeCmd = new DelegateCommand(OnVisibleRangeExecuted, OnVisibleRangeCanExecute); } } private ObservableCollection<AppointmentContainer> _collection; public ObservableCollection<AppointmentContainer> Collection { get { return _collection ?? (_collection = new ObservableCollection<AppointmentContainer>()); } } public ICommand VisibleRangeChangeCmd { get; private set; } private static bool? _isInDesignMode; public static bool IsDesignTime { get { if (!_isInDesignMode.HasValue) _isInDesignMode = DesignerProperties.IsInDesignTool; return _isInDesignMode.Value; } } private void OnVisibleRangeExecuted(object param) { var dateSpan = param as Telerik.Windows.Controls.ScheduleView.IDateSpan; if (dateSpan != null) GenerateAppointmentsSourceForTimeRange(dateSpan.Start, dateSpan.End); } private bool OnVisibleRangeCanExecute(object param) { return param != null; } /// <summary> /// Generates the appointments source for time range. /// </summary> /// <param name="startTime">The start time.</param> /// <param name="endTime">The end time.</param> protected void GenerateAppointmentsSourceForTimeRange(DateTime startTime, DateTime endTime) { Collection.Clear(); GenerateTypeOne(startTime, endTime); GenerateTypeTwo(startTime, endTime); } private void GenerateTypeTwo(DateTime startTime, DateTime endTime) { string subjectStr = string.Format("Subject - {0}", typeof (AppointmentTypeOne).Name); Collection.Add(new AppointmentContainer { AppointmentBase = new AppointmentTypeOne {Start = startTime.AddHours(3), End = startTime.AddHours(4), Subject = subjectStr} }); Collection.Add(new AppointmentContainer { AppointmentBase = new AppointmentTypeOne { Start = startTime.AddHours(8), End = startTime.AddHours(9), Subject = subjectStr } }); } private void GenerateTypeOne(DateTime startTime, DateTime endTime) { string subjectStr = string.Format("Subject - {0}", typeof(AppointmentTypeTwo).Name); Collection.Add(new AppointmentContainer { AppointmentBase = new AppointmentTypeTwo { Start = startTime.AddHours(6), End = startTime.AddHours(7), Subject = subjectStr } }); Collection.Add(new AppointmentContainer { AppointmentBase = new AppointmentTypeTwo { Start = startTime.AddHours(11), End = startTime.AddHours(12), Subject = subjectStr } }); } }Things show fine as expected when the application is lauched. But when I scroll up/down in the Daily view the appointment views which were initially visible just go blank. I was not able figure why this is happening intermittently. This problem can well understood if it is seen live. I would like to post repro project that I created.
Please help me in this problem
Thanks
-Obaid