in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Problem with data binding when the scheduler is not visible while adding data to the binded collection

Last post 05-26-2008 8:56 AM by C1_IrinaP. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 05-15-2008 2:17 PM

    Problem with data binding when the scheduler is not visible while adding data to the binded collection

    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);

    }

    }

    }

  • 05-15-2008 3:25 PM In reply to

    Re: Problem with data binding when the scheduler is not visible while adding data to the binded collection

    Update,

     It seems that it's not even needed to bind data to reproduce the problem.

    If the scheduler is in a property page, select another property page and return to the scheduler.

    Then , try to use the scheduler's scrollbar.  The scheduler won't refresh at all.

  • 05-15-2008 4:40 PM In reply to

    Re: Problem with data binding when the scheduler is not visible while adding data to the binded collection

    I'm not sure what is the source of problem, we'll investigate that.

    You can use the next workaround: subscribe to C1Scheduler.Loaded event and force Scheduler to rebuild UI in event handler:

    private void scheduler_Loaded(object sender, RoutedEventArgs e) 
    { 
      scheduler.BeginUpdate(); 
      scheduler.ClearValue(StyleProperty); 
      scheduler.ChangeStyle(scheduler.MonthStyle); 
      scheduler.EndUpdate(); 
    } 

    Please, let us know whether it helps you or if you find more information about this issue.

  • 05-15-2008 5:18 PM In reply to

    Re: Problem with data binding when the scheduler is not visible while adding data to the binded collection

    Yes, it did help.  It is pretty much the workaround I was looking for.  It seems to fix all the refresh problems so far.

     Thanks a lot.

  • 05-16-2008 3:46 PM In reply to

    Re: Problem with data binding when the scheduler is not visible while adding data to the binded collection

    Michael,

    thank you for reporting this problem. It will be fixed in the next version of control.
  • 05-26-2008 8:56 AM In reply to

    Re: Problem with data binding when the scheduler is not visible while adding data to the binded collection

    The fixed version is available for downloading:
    http://prerelease.componentone.com/dotnet30/c1wpfschedule/2008-t2/C1WPFScheduler.3.0.20082.52.zip
Page 1 of 1 (6 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.