public VerifyExpressionView() { InitializeComponent(); FieldGallery.ItemsSource = _items; _rootTreeViewItem = TreeViewItemInfo.CreateNew("All Fields"); DataContextChanged += OnDataContextChanged; }
public void AddSubItem(TreeViewItemInfo item) { if (_items.FirstOrDefault(x => x.Id == item.Id) == null) { _items.Add(item); } }
private async void ShowSubItemsOfTheNode(TreeViewItemInfo parentNode) { //This complex logic here is for the animation's sake. var itemsPresent = _items; var itemsToShow = new ObservableCollection<IFieldViewModel>(); var nodesToShow = parentNode.GetAllLevelSubItems(); if (nodesToShow.Any()) { itemsToShow.AddRange( nodesToShow.Select(n => _sourceFieldViewModels.First(vm => vm.Field.Id == n.Id))); itemsToShow = new ObservableCollection<IFieldViewModel>(itemsToShow.OrderBy(x => x.Field.Name)); } else { _items.Clear(); return; } var itemsToPreserve = itemsPresent.Intersect(itemsToShow).ToList(); var itemsToAdd = itemsToShow.Except(itemsToPreserve).ToList(); var itemsToRemove = itemsPresent.Except(itemsToPreserve).ToList(); if (itemsToRemove.Any()) { await RemoveItemsAsync(itemsToRemove, itemsPresent); } if (itemsToAdd.Any()) { await AddItemsAsync(itemsPresent, itemsToAdd); } if (itemsToPreserve.Any()) { foreach (var itemNode in itemsToPreserve) { var pos = itemsToShow.IndexOf(itemNode); itemsPresent.Remove(itemNode); itemsPresent.Insert(pos, itemNode); } } }
private void OnWindowClosed(object sender, EventArgs args) { var vm = sender as VerifyExpressionViewModel; if (vm == null) return; if (_previewPanel != null) { var behaviorCollection = Interaction.GetBehaviors(_previewPanel); var moveBehavior = behaviorCollection.FirstOrDefault(x => x is FluidMoveBehavior) as FluidMoveBehavior; if (moveBehavior != null) { moveBehavior.IsActive = false; moveBehavior.Detach(); behaviorCollection.Remove(moveBehavior); } foreach (var child in _previewPanel.Children) { var cp = child as ContentPresenter; if (cp != null) { cp.Content = null; cp.ContentTemplate = null; cp.DataContext = null; } } _previewPanel.Children.Clear(); _previewPanel = null; } _items.Clear(); _treeViewItems.Clear(); _sourceFieldViewModels.Clear(); _rootTreeViewItem.ClearSubItems(); _rootTreeViewItem = null; ExpressionTestFields.Clear(); DataContext = null; DataContextChanged -= OnDataContextChanged; vm.PropertyChanged -= OnDataContextPropertyChanged; vm.Closed -= OnWindowClosed; }