protected override void OnVisualRemoved(UIElement elt) { Viewport2DVisual3D model = elt.GetValue(LinkedModelProperty) as Viewport2DVisual3D; _modelContainer.Children.Remove(model); LoginGrid loginGrid = (LoginGrid)model.Visual; loginGrid.imgMoveToLeft.MouseDown -= MoveToLeft; loginGrid.imgMoveToRight.MouseDown -= MoveToRight; model.ClearValue(LinkedElementProperty); elt.ClearValue(LinkedModelProperty); SelectedIndex = 0; // Update SelectedIndex if needed if (SelectedIndex >= 0 && SelectedIndex < VisibleChildrenCount) { ReflowItems(); } else { SelectedIndex = Math.Max(0, Math.Min(SelectedIndex, VisibleChildrenCount - 1)); } }
protected override void OnVisualRemoved(UIElement elt) { Viewport2DVisual3D model = elt.GetValue(LinkedModelProperty) as Viewport2DVisual3D; _modelContainer.Children.Remove(model); model.ClearValue(LinkedElementProperty); elt.ClearValue(LinkedModelProperty); SelectedIndex = 0; // Update SelectedIndex if needed if (SelectedIndex >= 0 && SelectedIndex < VisibleChildrenCount) { ReflowItems(); } else { SelectedIndex = Math.Max(0, Math.Min(SelectedIndex, VisibleChildrenCount - 1)); } //load current tab Viewport2DVisual3D newSelectedModel = (Viewport2DVisual3D)_modelContainer.Children[SelectedIndex]; ListBoxItem item = (ListBoxItem)newSelectedModel.GetValue(LinkedElementProperty); RaiseTabLoadedEvent((Tab)item.Content); }