I have a TreeListView in my application and it has a timer that refresh the TreeListView each 30 seconds obtaining the new ItemSource from a web service. If I asign the new data for the TreeListView to the ItemSource every 30 sec. the full tree and the rowdetails collapse, so to avoid that problem I have implemented the INotifyPropertyChanged interface, so if I make any change in the original structure the TreeListView show them without collapsing nodes or rowdetails. So that's why I need to merge the old TreeListView and the new TreeListView into the old one, adding or removing nodes in the original TreelistView. My tree structure is:
public class Tree : INotifyPropertyChanged
{
private List<Object> data;
private ObservableCollection<Tree> childnodes;
public Tree(List<Object> list)
{
info = list;
Nodes = new ObservableCollection<Tree>();
}
public List<Object> info
{
get { return data; }
set
{
data = value;
NotifyPropertyChanged( this, "info");
}
}
public ObservableCollection<Tree> Nodes
{
get { return childnodes; }
set {
childnodes= value;
NotifyPropertyChanged( this, "Nodes");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(object sender, string propertyName)
{
if (this.PropertyChanged != null)
{
PropertyChanged(sender, new PropertyChangedEventArgs(propertyName));
}
}
}
And in the codeBehind:
....
if (radTreeListView.ItemsSource == null) //The first time
{
original_tree = TreeService.GetTreeData(workflows); //Returns an ObservableCollection<Tree>
radTreeListView.ItemsSource = original_tree;
}
else //Merge the new treeListView into the original (second and succesive times)
{
new_tree = TreeService.GetTreeData(workflows); //Returns the new ObservableCollection<Tree>
MergeTrees (original_tree, new_tree);
}
....
Any idea to implement the MergeTrees function?