in

C1 Community

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

Binding to ObservableCollection<T>

Last post 06-16-2008 1:23 PM by duydoan. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 06-14-2008 1:46 PM

    Binding to ObservableCollection<T>

    Hi,
    I'm trying to do this but nothing happen.

    The xaml:
    <c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.DataSource"
    Value="{Binding ElementName=MySelf, Path=ListSource, Mode=OneWay}"/>

    <c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.IdMapping.MappingName" Value="ScheduleUID" />
    <c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.Subject.MappingName" Value="Subject"/>
    <c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.Body.MappingName" Value="Content"/>
    <c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.Start.MappingName" Value="StartDate"/>
    <c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.End.MappingName" Value="EndDate"/>
    <c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.Location.MappingName" Value="Location"/>
    <c1sched:NestedPropertySetter PropertyName="DataStorage.AppointmentStorage.Mappings.AppointmentProperties.MappingName" Value="Properties"/>

    The cs:
    private ObservableCollection<T> listSource;
    public ObservableCollection<T> ListSource
    {
      get { return listSource; }
     
    set { listSource = value; }
    }

    private void MySelf_Loaded(object sender, RoutedEventArgs e)
    {
        listSource =
    new ObservableCollection<T>(List<T>));
        C1ScheduleMain.DataStorage.AppointmentStorage.ResetBindings(
    false);
    }

    The list contains 2 records but there's no appointment appears.

    Thanks for advice

    D.

     

  • 06-14-2008 3:12 PM In reply to

    Re: Binding to ObservableCollection<T>

    I can say nothing relying on your code. What is MySelf, what is T?

    Please, post here the full xaml and cs for the sample window or page.
  • 06-15-2008 1:38 AM In reply to

    Re: Binding to ObservableCollection<T>

    Thank you for your concern. Here's the full code. Actually i'm evaluating the trial version and it's expired. Don't know expiration will affect how component work.

    The Schedule class:

    using System;
    using System.Collections;
    using System.Runtime.Serialization;

    namespace WpfApplication2{
    public class Schedule
    {
    private string scheduleUID;
    private string subject;
    private string content;

     

    private DateTime startDate;

    private DateTime endDate;

     

    private string location;

     

    private string properties;

     

    public Schedule()

    {

     

    }

    public string ScheduleUID

    {

    get { return scheduleUID; }set { this.scheduleUID = value; }

    }

     

    public string Subject

    {

    get { return subject; }set { this.subject = value; }

    }

     

    public string Content

    {

    get { return content; }set { this.content = value; }

    }

     

    public DateTime StartDate

    {

    get { return startDate; }set { this.startDate = value; }

    }

     

    public DateTime EndDate

    {

    get { return endDate; }set { this.endDate = value; }

    }

     

    public string Location

    {

    get { return location; }set { this.location = value; }

    }

     

    public string Properties

    {

    get { return properties; }set { this.properties = value; }

    }

     

    }
    }

     

    The xaml:

    <Window

    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"

     

    x:Class="WpfApplication2.Window1"

    x:Name="MySelf"

    Title="Window1" Height="600" Width="800"

    Loaded="MySelf_Loaded">

     

    <Grid>

    <c1sched:C1Scheduler x:Name="C1ScheduleMain" Cursor="Hand"

    Style="{DynamicResource {ComponentResourceKey ResourceId=WeekStyle, TypeInTargetAssembly={x:Type c1sched:C1Scheduler}}}"

    Theme="{DynamicResource {ComponentResourceKey ResourceId=Office2007.Black, TypeInTargetAssembly={x:Type c1sched:C1Scheduler}}}"

    AutoScrollToFirstAppointment="True" FirstVisibleTime="07:00:00">

    <c1sched:NestedPropertySetter

    PropertyName="DataStorage.AppointmentStorage.Mappings.IdMapping.MappingName" Value="ScheduleUID" />

    <c1sched:NestedPropertySetter

    PropertyName="DataStorage.AppointmentStorage.Mappings.Subject.MappingName" Value="Subject"/>

    <c1sched:NestedPropertySetter

    PropertyName="DataStorage.AppointmentStorage.Mappings.Body.MappingName" Value="Content"/>

    <c1sched:NestedPropertySetter

    PropertyName="DataStorage.AppointmentStorage.Mappings.Start.MappingName" Value="StartDate"/>

    <c1sched:NestedPropertySetter

    PropertyName="DataStorage.AppointmentStorage.Mappings.End.MappingName" Value="EndDate"/>

    <c1sched:NestedPropertySetter

    PropertyName="DataStorage.AppointmentStorage.Mappings.Location.MappingName" Value="Location"/>

    <c1sched:NestedPropertySetter

    PropertyName="DataStorage.AppointmentStorage.Mappings.AppointmentProperties.MappingName" Value="Properties"/>

    <c1sched:NestedPropertySetter

    PropertyName="DataStorage.AppointmentStorage.DataSource"

    Value="{Binding ElementName=MySelf, Path=ListSource, Mode=OneWay}"/>

    </c1sched:C1Scheduler>

    </Grid>

    </Window>

    and code behind:

    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.Navigation;

    using System.Windows.Shapes;

    namespace WpfApplication2

    {

    public partial class Window1 : Window

    {

    private ObservableCollection<Schedule> listSource;

     

    public Window1()

    {

    InitializeComponent();

    //

    listSource = new ObservableCollection<Schedule>();

    }

     

    public ObservableCollection<Schedule> ListSource

    {

    get { return listSource; }set { listSource = value; }

    }

    private void MySelf_Loaded(object sender, RoutedEventArgs e)

    {

    Schedule _item = new Schedule();

    _item.ScheduleUID = System.Guid.NewGuid().ToString();

    _item.Subject = "Appointment 1";

    _item.Content = "";

    _item.Location = "Office";

    _item.StartDate = DateTime.Now;_item.EndDate = DateTime.Now.AddDays(1);

     

    listSource.Add(_item);

    C1ScheduleMain.DataStorage.AppointmentStorage.ResetBindings(
    false);

    }

     

    }

    }

  • 06-15-2008 5:45 AM In reply to

    Re: Binding to ObservableCollection<T>

    Some corrections:

    1. Add the next namespace definition to  your Window1.xaml:

     xmlns:local="clr-namespace:WpfApplication2"
     

    2. Change DataSource setter: 

       <sch:NestedPropertySetter
        PropertyName="DataStorage.AppointmentStorage.DataSource"
        Value="{Binding Path=ListSource, RelativeSource={RelativeSource AncestorType={x:Type local:Window1}}, Mode=TwoWay}"/>

    3. Change type of ScheduleUID property from string to Guid.

    ps: expiration doesn't affect component functionality.

  • 06-15-2008 12:03 PM In reply to

    Re: Binding to ObservableCollection<T>

    Thanks you, it works like on TV.

    By the way, i think C1 should add more code sample for this and some special features like PropertyBridge Binding. There's quite short of code sample in integrated help. It will save lots of time for us.

  • 06-15-2008 3:03 PM In reply to

    Re: Binding to ObservableCollection<T>

    One more thing raised after tested this binding method, i need to change binding at runtime, let says i have another ListSource1, how can i do that. Can not use DataSource = ListSource1 and AppointmentStorage doesn't have SetBindings method.

    Thanks.

  • 06-15-2008 4:28 PM In reply to

    Re: Binding to ObservableCollection<T>

    > One more thing raised after tested this binding method, i need to change binding at > runtime, let says i have another ListSource1, how can i do that. Can not use DataSource > = ListSource1 and AppointmentStorage doesn't have SetBindings method.

    Why can't use DataSource = ListSource1? All these settings can be changed from code. Just set these properties from code. Something like that:

    this.c1Schedule1.DataStorage.AppointmentStorage.Mappings.AppointmentProperties.MappingName = "Properties"; this.c1Schedule1.DataStorage.AppointmentStorage.Mappings.Body.MappingName = "Body"; this.c1Schedule1.DataStorage.AppointmentStorage.Mappings.End.MappingName = "End"; this.c1Schedule1.DataStorage.AppointmentStorage.Mappings.IdMapping.MappingName = "Id"; this.c1Schedule1.DataStorage.AppointmentStorage.Mappings.Location.MappingName = "Location"; this.c1Schedule1.DataStorage.AppointmentStorage.Mappings.Start.MappingName = "Start"; this.c1Schedule1.DataStorage.AppointmentStorage.Mappings.Subject.MappingName = "Subject"; this.c1Schedule1.DataStorage.AppointmentStorage.DataSource = ListSource1;

  • 06-16-2008 1:23 PM In reply to

    Re: Binding to ObservableCollection<T>

    Sorry, my developer gave me wrong information. I tested myself, it works.

    Thanks again for your time.

Page 1 of 1 (8 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.