开发者

WPF Binding not updating when binded object is updated

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

<my:GanttChartTaskListView Name="ganttChartTaskListView1" ItemsSource="{Binding Source={x:St开发者_如何学编程atic 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜