private void RebuildTree() { treeFolders.Clear(); treeView.Root.Children.Clear(); // Create and add nodes to dictionary foreach (var folder in AppState.Folders.Values) { var vmFolder = new SubscriptionFolderViewModel(folder); var tvFolder = new SortedTreeViewNode <SubscriptionItemViewModelBase, string>(vmFolder); treeFolders.Add(folder.Id, tvFolder); } // Parent all the nodes foreach (var pair in treeFolders) { GetParentFolder(pair.Value.Data.ParentId).Children.Add(pair.Value); } // Create subscription leafs foreach (var sub in AppState.Subscriptions.Values) { AddSubscription(sub); } }
private void Folders_DictionaryChanged(object sender, DictionaryChangedEventArgs <int, ApiSubscriptionFolder> e) { if (e.Action == NotifyCollectionChangedAction.Reset || e.Action == NotifyCollectionChangedAction.Replace) { RebuildTree(); } else { foreach (var oldItem in e.OldItems) { RemoveFolder(oldItem.Value); } // Add all the folders first foreach (var newItem in e.NewItems) { var vmFolder = new SubscriptionFolderViewModel(newItem.Value); var tvFolder = new SortedTreeViewNode <SubscriptionItemViewModelBase, string>(vmFolder); treeFolders.Add(newItem.Key, tvFolder); } // And then parent them foreach (var newItem in e.NewItems) { var tvFolder = treeFolders[newItem.Key]; GetParentFolder(tvFolder.Data.ParentId).Children.Add(tvFolder); } } StateHasChanged(); }