Hi,
Anyone has a workaround for this?
The C1Scheduler is binded to an observable collection.
I can add and remove items from the collection and the scheduler is updated correctly.
However, as soon as I hide the scheduler and try to add data to the data source again, the scheduler does not refresh anymore.
To reproduce the problem, use the provided sample.
The sample is a simple property sheet with the first page containing the scheduler an the second page containing nothing.
You just have to select the second property tab and try to add data to the collection by using the buttons in the toolbar.
When you return to the first tab, you can see that the scheduler is not updated with the new data.
At this point, the scheduler won't react to any update, even if it is visible.
Here is the sample code:
==================== XAML =========================
<
Window x:Class="SchedulerTester.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c1sched="http://schemas.componentone.com/wpf/C1Schedule"
Title="SchedulerTester" Height="600" Width="600"
Name="window1"
>
<Grid>
<
Grid.RowDefinitions><RowDefinition Height="Auto"/>
<
RowDefinition/></Grid.RowDefinitions>
<
ToolBar Grid.Row="0"><StackPanel Orientation="Horizontal">
<
Button Click="OnAdd"><TextBlock>Add</TextBlock>
</
Button><Button Click="OnClear">
<
TextBlock>Clear</TextBlock></Button>
<
Button Click="OnClearAndAdd"><TextBlock>Clear + 10 add</TextBlock>
</
Button></StackPanel>
</
ToolBar><TabControl Grid.Row="1">
<
TabItem Header="Scheduler"><c1sched:C1Scheduler Name="scheduler" Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly=c1sched:C1Scheduler, ResourceId=MonthStyle}}" FirstVisibleTime="07:00:00">
<!--
Map AppointmentStorage --><c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.Body.MappingName" Value="Body"/>
<
c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.Subject.MappingName" Value="Subject"/><c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.Location.MappingName" Value="Location"/>
<
c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.Start.MappingName" Value="StartTime"/><c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.End.MappingName" Value="EndTime"/>
<
c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.DurationMapping.MappingName" Value="Duration"/>
<
c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.DataSource"Value="{Binding ElementName=window1, Path=AppointmentCollection, Mode=OneWay}" />
</
c1sched:C1Scheduler></TabItem>
<
TabItem Header="Empty tab"/></TabControl>
</
Grid></Window>
==============================================================
===========================C#=================================
using
System;
using
System.Collections.Generic;
using
System.Collections.ObjectModel;
using
System.Text;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Data;
using
System.Windows.Documents;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Imaging;using System.Windows.Shapes;
namespace SchedulerTester
{
public class TestAppointment
{
private string subject = string.Empty;
private DateTime startTime = DateTime.Now;private DateTime endTime = DateTime.Now;
private TimeSpan duration = new TimeSpan();private string body = string.Empty;public string Subject
{
get { return this.subject; }set { this.subject = value; }
}
public DateTime StartTime
{
get { return this.startTime; }set { this.startTime = value; }
}
public DateTime EndTime
{
get { return this.endTime; }set { this.endTime = value; }
}
public TimeSpan Duration
{
get { return this.duration; }set { this.duration = value; }
}
public string Body
{
get { return this.body; }set { this.body = value; }
}
public string Location
{
get { return string.Empty; }set { }
}
}
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : System.Windows.Window
{
private ObservableCollection<TestAppointment> appointmentCollection = new ObservableCollection<TestAppointment>();
TimeSpan duration = new TimeSpan(0, 60, 0);DateTime startDate = DateTime.Now;public ObservableCollection<TestAppointment> AppointmentCollection
{
get { return this.appointmentCollection; }set { this.appointmentCollection = value; }
}
public Window1()
{
InitializeComponent();
}
public void OnAdd(object sender, RoutedEventArgs args)
{
this.startDate = this.startDate.AddDays(1);
TestAppointment appointment = new TestAppointment();appointment.Duration = this.duration;
appointment.StartTime =
this.startDate;appointment.EndTime = this.startDate.AddMinutes(duration.TotalMinutes);
this.AppointmentCollection.Add(appointment);this.scheduler.DataStorage.AppointmentStorage.ResetBindings(false);
this.scheduler.InvalidateArrange();this.scheduler.InvalidateMeasure();this.scheduler.InvalidateVisual();
}
public void OnClear(object sender, RoutedEventArgs args)
{
this.AppointmentCollection.Clear();this.scheduler.DataStorage.AppointmentStorage.ResetBindings(false);
}
public void OnClearAndAdd(object sender, RoutedEventArgs args)
{
this.AppointmentCollection.Clear();for (int i = 0; i < 10; i++)
{
this.startDate = this.startDate.AddDays(1);TestAppointment appointment = new TestAppointment();
appointment.Duration =
this.duration;appointment.StartTime = this.startDate;
appointment.EndTime =
this.startDate.AddMinutes(duration.TotalMinutes);this.AppointmentCollection.Add(appointment);
}
this.scheduler.DataStorage.AppointmentStorage.ResetBindings(false);
}
}
}