A little back story here. I've got a public property (typeof(ObservableCollection<Area>)) that I bind a treeview to. I'd like to update the tree, but I don't want to redraw the whole thing and lose the selected item, collapsed/expanded states of nodes and anything else I forget to implement. So I think I need to update the Area within the collection. I notice that using a FirstOrDefault statement and setting it equal to something does not actually change the Area in the observable collection:
var areas = GetAreaInfo(); //Entity Framework query returns ObservableCollection<Area>
foreach (Area a in areas)
{
var αrea = Areas.FirstOrDefault(α => α.Id == a.Id);
if (αrea != null)
αrea = a; //αrea changes, but Area[0] which is supposed to be αrea doesn't
}
Can I get a reference or pointer to the object so I don't have to iterate through the observable collection and use indexes?
αfor a lambda is fine but if you useareaandαreain my code base, prepare for nightmares. Yes, this is a threat.