private void boxesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { //VIEW0 int i = 0; if (e.NewItems != null) foreach (var newBoxViewModel in e.NewItems.Cast<BoxViewModel>()) { var boxIndex = e.NewStartingIndex + i; var box = new Box(newBoxViewModel, ((Box)this.Parent).CaretPerTree); this.locations.Insert(boxIndex, default(Point)); this.Children.Insert(boxIndex, box); SetLeft(box, 0); SetTop(box, 0); newBoxViewModel.PropertyChanged += (_, _e) => { //if (_e.PropertyName == nameof(BoxViewModel.Layout))//TODO: filter all calls to the following method by only propagating those properties that cause a layout change this.boxLayoutChanged(); }; } //VIEW1//VIEW2 if (e.OldItems != null) foreach (var newBoxViewModel in e.OldItems.Cast<BoxViewModel>()) { this.locations.RemoveAt(e.OldStartingIndex); this.Children.RemoveAt(e.OldStartingIndex); } }
/// <summary> Gets the box corresponding to the specified box view model. </summary> internal static Box GetViewModelBox(BoxViewModel model, Box anyBox) { //TODO: change this ugly method of getting the box corresponding to a box model Box root = GetRootBox(anyBox); var result = root.TransitiveSelect(b => b.Children.OfType<BoxComposition>().SelectMany(boxComposition => boxComposition.Children.Cast<Box>())) .First(b => b.viewModel == model); return result; }
/// <summary> Initializes the root box and sets it as child in this host. </summary> public void InitializeComponents() { Root = new Box(); this.Child = Root; }
private static Box GetRootBox(Box box) { return GetVisualParents(box).OfType<Box>().Last(); }