public void PersistChildren() { var persistState = new PersistState(); foreach (TabItem tab in TabHost.Items) { // Save child grid column-sizes var grid = tab.GetChildrenOf <Grid>().FirstOrDefault(); if (grid != null && GridColumnSizeHelper.GetSaveGridColumnsSize(grid)) { GridColumnSizeHelper.SaveColumnSizes(grid); } // Save open tab's state if (tab.Content is IPersistableTab) { IPersistableTab saveTab = (IPersistableTab)tab.Content; var data = saveTab.SaveData(); if (data != null) { persistState.Tabs.Add(new TabState { PluginType = saveTab.Plugin.GetType(), ViewType = saveTab.ViewType, DataInstance = saveTab.SaveData() }); } } } persistState.SelectedTabIndex = TabHost.SelectedIndex; ClientState.Current.Context.SaveSettingTo("state.xml", persistState); }
void CreatePluginColumns() { int i; var disabled = DebugKeys.DisabledPlugins; var columns = PluginsManager.Current.Plugins .Where(p => p.Colomn != null) .Where(p => !disabled.Contains(p.Name)) .OrderBy(p => p.Name) .Select(p => p.Colomn) .ToList(); // Create a column for each plugin for (i = 0; i < columns.Count; i++) { var control = columns[i].CreateColumnView(); var def = new ColumnDefinition { Width = new GridLength(columns[i].PreferredWidth, GridUnitType.Star) }; OverviewContainerRootGrid.ColumnDefinitions.Add(def); OverviewContainerRootGrid.Children.Add(control); Grid.SetColumn(control, i); GridSplitter splitter = null; if (i < columns.Count - 1) { splitter = CreateSplitter(); OverviewContainerRootGrid.Children.Add(splitter); Grid.SetColumn(splitter, i); } var button = GetChildCollapseButton((FrameworkElement)control); // Attach collapse functionality to button if (button != null) { GridColumnSizeHelper.SetCollapseAction(def, () => CollapseColumn(splitter, def, button.Content.ToString())); button.Click += delegate { GridColumnSizeHelper.GetCollapseAction(def)(); }; } } // Add ColumnCollapseView collapseView = new ColumnCollapseView(); OverviewContainerRootGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0, GridUnitType.Auto) }); OverviewContainerRootGrid.Children.Add(collapseView); Grid.SetColumn(collapseView, i++); List <object> storedColumns; bool success = GridColumnSizeHelper.SetColumnSizes(OverviewContainerRootGrid, out storedColumns); // See if column was collapsed the last time we saved app state if (success) { foreach (var def in OverviewContainerRootGrid.ColumnDefinitions) { if (def.Width.Value == 0) { // First set old width so that expand/save logic gets executed correctly def.Width = GridColumnSizeHelper.GetPreviousGridLength(def); Action x = GridColumnSizeHelper.GetCollapseAction(def); // Execute collapse action defined when column was created if (x != null) { x(); } } } } }
void CollapseColumn(GridSplitter splitter, ColumnDefinition def, string content) { // Ignore collapse if popup is opened if (PopupManager.ActivePopup != null) { return; } int collapsed = 0; // Count the number of collapsed items (exclusing collapseView and rockScroll) for (int i = 0; i < OverviewContainerRootGrid.ColumnDefinitions.Count - 2; i++) { if (OverviewContainerRootGrid.ColumnDefinitions[i].Width.Value == 0) { collapsed++; } } // Only allowed to collapse when there are at least two columns which have Width > 0 if (collapsed >= OverviewContainerRootGrid.ColumnDefinitions.Count - 3) { return; } GridColumnSizeHelper.SetPreviousGridLength(def, def.Width); //Start Collapse Column Animation, only when the column Width != 0 if (def.Width != new GridLength(0)) { Storyboard CollapseColumnGrid = (Storyboard)FindResource("CollapseColumn"); Storyboard.SetTarget(CollapseColumnGrid, def); GridLengthAnimation gla = CollapseColumnGrid.Children[0] as GridLengthAnimation; gla.From = def.Width; gla.To = new GridLength(0); CollapseColumnGrid.Begin(this); } if (splitter != null) { splitter.IsEnabled = false; } collapseView.AddCollapsedView(def, content, delegate { //Start Expand Column Animation, only when the column Width = 0 if (def.Width == new GridLength(0)) { def.Width = GridColumnSizeHelper.GetPreviousGridLength(def); GridLength previousWidth = def.Width; def.Width = new GridLength(0); Storyboard ExpandColumnGrid = (Storyboard)FindResource("CollapseColumn"); Storyboard.SetTarget(ExpandColumnGrid, def); GridLengthAnimation gla = ExpandColumnGrid.Children[0] as GridLengthAnimation; gla.From = new GridLength(0); gla.To = previousWidth; ExpandColumnGrid.Begin(this); } if (splitter != null) { splitter.IsEnabled = true; } }); }