views:

47

answers:

1

I'm trying to bind to a custom control like so:

<my:GanttChartTaskListView Name="ganttChartTaskListView1" ItemsSource="{Binding Source={x:Static local:TaskCollection.taskList}}" />

In my WPF Window constructor I add add an item to my taskList, when it loads I can see that item in my custom control, however, when I subsequently add items it does not update. I tried setting Mode=TwoWay, however, then it says the "Path" is required and I'm not familiar with binding like that (this is new to me).

Here is my TaskCollection class:

namespace ProjectManager
{
    public static class TaskCollection
    {
        private static List<TaskItem> _taskList = new List<TaskItem>();

        public static List<TaskItem> taskList
        {
            get  {return _taskList; }
            set { _taskList = value; }
        }
    }
}

Any ideas? Is there a better / easier way to do this?

+4  A: 

The WPF system has to be told that the an item has been added to the list.

The simplest way is to bind to a System.Collections.ObservableCollection<TaskItem>, instead of List<TaskItem>, which will raise a notification when the collection changes.

Jay
Thanks, you are a God amongst men
Chris Klepeis