开发者

WPF bound object update notification

I have a TreeView with a few objects bound to it, let's say something like this:

public class House
    {
        public List<Room> Rooms { get; set; }
        public List<Person> People { get; set; }

        public House()
        {
            this.Rooms = new List<Room>();
            this.People = new List<Person>();
        }

        public void BuildRoom(string name)
        {
            this.Rooms.Add(new Room() { Name = name });
        }

        public void DestroyRoom(string name)
        {
            this.Rooms.Remove(new Room() { Name = name });
        }

        public void PersonEnter(string name)
        {
            this.People.Add(new Person() { Name = name });
        }

        public void PersonLeave(string name)
        {
            this.People.Remove(new Person() { Name = name });
        }
    }

    public class Room
    {
        public string Name { get; set; }
    }

    public class Person
    {
        public string Name { get; set; }
    }

The TreeView is watching over the House object, whenever a room is built / destroyed or a person enters / leaves, my tree view updates itself to show the new state of the house (I omitted some implementation details for simplicity).

What I want is to know the exact moment when this update finishes, so I can do something right there, the thing is that I cre开发者_开发技巧ated an indicator of the selected item, and when something moves, I need to update said indicator's position, that's the reason I need it exactly when the tree view updates.

Let me know if you know a solution to this.

Also, the code is not perfect (DestroyRoom and PersonLeave), but you get the idea.

Thanks!


Use an ObservableCollection<T> and wrap it in a CollectionView to get a bindable CurrentItem.

http://msdn.microsoft.com/en-us/library/system.windows.data.collectionview_members.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜