/// <summary> /// select UIElement by current tab /// </summary> /// <param name="current"></param> public void SelectIndexByTab(Tab current) { for (int i = 0; i < _modelContainer.Children.Count; i++) { Viewport2DVisual3D newSelectedModel = (Viewport2DVisual3D)_modelContainer.Children[i]; ListBoxItem item = (ListBoxItem)newSelectedModel.GetValue(LinkedElementProperty); if (current.Id == ((Tab)item.Content).Id) { SelectedIndex = i; return; } } }
protected override void OnContainerLeftButtonDown(object sender, MouseButtonEventArgs e) { Viewport2DVisual3D model = e.Source as Viewport2DVisual3D; if (model != null) { SelectedIndex = _modelContainer.Children.IndexOf(model); //raise event to load ListBoxItem item = (ListBoxItem)model.GetValue(LinkedElementProperty); RaiseTabLoadedEvent((Tab)item.Content); } }
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); }