public override void OnApplyTemplate()
        {
            if (SymbolCategories != null)
            {
                SymbolCategories.SelectionChanged -= SymbolCategories_SelectionChanged;
            }

            if (Symbols != null)
            {
                Symbols.SelectionChanged -= Symbols_SelectionChanged;
            }

            base.OnApplyTemplate();

            SymbolCategories = GetTemplateChild(PART_SYMBOLCATEGORIES) as ComboBox;

            if (SymbolCategories != null)
            {
                SymbolCategories.SelectionChanged += SymbolCategories_SelectionChanged;
            }

            Symbols = GetTemplateChild(PART_SYMBOLS) as ListBox;

            if (Symbols != null)
            {
                Symbols.SelectionChanged += Symbols_SelectionChanged;
            }

            SymbolsScrollViewer = GetTemplateChild(PART_SYMBOLSSCROLLVIEWER) as ScrollViewer;

            LayoutRoot = GetTemplateChild(PART_LAYOUTROOT) as FrameworkElement;

            getSymbolCategories();

            if (Symbols != null)
            {
                // Size width of symbols wrap panel to fit within parent ListBox
                Dispatcher.BeginInvoke((Action) delegate()
                {
                    SymbolsWrapPanel = ControlTreeHelper.FindChildOfType <WrapPanel>(Symbols, 5);
                    if (SymbolsWrapPanel != null && double.IsNaN(SymbolsWrapPanel.Width) && !double.IsNaN(Symbols.ActualWidth) && Symbols.ActualWidth > 0)
                    {
                        SymbolsWrapPanel.Width = SymbolsScrollViewer.ViewportWidth - 2;
                        Symbols.SizeChanged   -= Symbols_SizeChanged;
                        Symbols.SizeChanged   += Symbols_SizeChanged;
                    }
                });
            }
            isInitialized = true;

            if (InitCompleted != null)
            {
                InitCompleted(this, EventArgs.Empty);
            }
        }
        public void ToggleVisibility(bool visible)
        {
            Visibility visibility = visible ? Visibility.Visible : System.Windows.Visibility.Collapsed;

            if (Container == null)
            {
                InitialVisibility = visibility;
                return;
            }

            if (visibility == Container.Visibility)
            {
                return;
            }

            #region showHideRibbonTabs
            if (TabControl != null)
            {
                if (visible)
                {
                    previouslyVisibleTabIndices.Clear();
                    TabControl.SelectedIndex = 0;
                }
                else if (TabControl.SelectedIndex == 0)
                {
                    TabControl.SelectedIndex = 1;
                }

                Grid mainGrid = ControlTreeHelper.FindChildOfType <Grid>(TabControl);
                if (mainGrid != null && mainGrid.Children.Count > 0)
                {
                    Grid templateTop = mainGrid.Children[0] as Grid;
                    if (templateTop != null && templateTop.Children.Count > 1)
                    {
                        Border border = templateTop.Children[1] as Border;
                        if (border != null)
                        {
                            border.Visibility = visible ? Visibility.Collapsed : Visibility.Visible;
                        }
                    }
                }
            }
            #endregion

            ShowBackStage(visible);

            //TODO:- EVAL
            //if (visible)
            //    View.HideSearchUI();
        }
示例#3
0
        /// <summary>
        /// Fires when the associated Popup is opened
        /// </summary>
        private void Popup_Opened(object sender, EventArgs e)
        {
            if (Application.Current != null && Application.Current.RootVisual != null)
            {
                // Find the Grid that is closest to the root of the application's visual tree
                if (rootGrid == null)
                {
                    rootGrid = ControlTreeHelper.FindChildOfType <Grid>(Application.Current.RootVisual);
                }

                if (rootGrid != null)
                {
                    // Create the overlay grid
                    if (overlay == null)
                    {
                        // Make the overlay grid almost transparent, but not completely so.  Elements that are
                        // completely transparent cannot intercept clicks.
                        overlay = new Grid()
                        {
                            Background          = new SolidColorBrush(Color.FromArgb(1, 255, 255, 255)),
                            HorizontalAlignment = HorizontalAlignment.Stretch,
                            VerticalAlignment   = VerticalAlignment.Stretch
                        };

                        // Set the column and row span of the overlay so that it covers the entire grid

                        if (rootGrid.ColumnDefinitions.Count > 0)
                        {
                            Grid.SetColumnSpan(overlay, rootGrid.ColumnDefinitions.Count);
                        }

                        if (rootGrid.RowDefinitions.Count > 0)
                        {
                            Grid.SetRowSpan(overlay, rootGrid.RowDefinitions.Count);
                        }

                        // Listen to click events on the overlay
                        overlay.MouseLeftButtonDown  += Overlay_Click;
                        overlay.MouseRightButtonDown += Overlay_Click;
                    }

                    // Insert the overlay into the grid
                    rootGrid.Children.Add(overlay);
                }
            }
        }