WPF bound object update notification
- by Carlo
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 created 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!