/// <summary> /// Adds a new button to the Intelligence Portal header. /// </summary> /// <param name="headerButtonCaption">The caption to display in the button.</param> /// <param name="headerButtonTooltip">The text to display in the tooltip when a user hovers the mouse over the button.</param> /// <param name="buttonCommand">The command to run when the button is clicked.</param> public void RegisterHeaderCommand( string headerButtonCaption, string headerButtonTooltip, SimpleCommand buttonCommand) { // We may well be called before the header bar is actually on screen, so // we need to loop until it's there (or the initialization code times us out) var timer = mContainer.Resolve <IDispatcherTimer>(); timer.Interval = TimeSpan.FromMilliseconds(10); timer.Tick += delegate { var toolboxView = Application.Current.RootVisual.GetVisualDescendants().OfType <ToolboxView>().SingleOrDefault(); if (toolboxView == null) { // Toolbox not visible yet. return; } // Toolbox is visible now. timer.Stop(); // Find the grid that contains the buttons var layoutGrid = (Grid)toolboxView.Content; var grid2 = (Grid)layoutGrid.Children[0]; var grid3 = (Grid)grid2.Children[0]; var grid4 = (Grid)grid3.Children[0]; var destinationGrid = grid4; // Add a new column definition var existingColCount = destinationGrid.ColumnDefinitions.Count; destinationGrid.ColumnDefinitions.Add(new ColumnDefinition()); // Add the button. var button = new HeaderButton(); button.HeaderButtonTextBlockBase.Text = headerButtonCaption; button.HeaderButtonTextBlockHighlight.Text = headerButtonCaption; var tooltip = ToolTipService.GetToolTip(button.ButtonControl) as ToolTip; if (tooltip != null) { tooltip.Content = headerButtonTooltip; } button.ButtonControl.Command = buttonCommand; button.SetValue(Grid.ColumnProperty, existingColCount); destinationGrid.Children.Add(button); }; timer.Start(); }
/// <summary> /// Adds a new button to the Intelligence Portal header. /// </summary> /// <param name="headerButtonCaption">The caption to display in the button.</param> /// <param name="headerButtonTooltip">The test to display in the tooltip when a user hivers the mouse over the button.</param> /// <param name="buttonCommand">The command to run when the button is clicked.</param> public void RegisterHeaderCommand( string headerButtonCaption, string headerButtonTooltip, SimpleCommand buttonCommand) { // Unfortunately we may well be called before the header bar is actually on screen, so // we need to loop until it's there (or the initialization code times us out) var timer = mContainer.Resolve<IDispatcherTimer>(); timer.Interval = TimeSpan.FromMilliseconds(10); timer.Tick += delegate { var toolboxView = Application.Current.RootVisual.GetVisualDescendants().OfType<ToolboxView>().SingleOrDefault(); if (toolboxView == null) { // Toolbox not visible yet. return; } // Toolbox is visible now. timer.Stop(); // Find the grid that contains the buttons var layoutGrid = (Grid)toolboxView.Content; var grid2 = (Grid)layoutGrid.Children[0]; var grid3 = (Grid)grid2.Children[0]; var grid4 = (Grid)grid3.Children[0]; var destinationGrid = grid4; // Add a new column definition var existingColCount = destinationGrid.ColumnDefinitions.Count; destinationGrid.ColumnDefinitions.Add(new ColumnDefinition()); // Add the button. var button = new HeaderButton(); button.HeaderButtonTextBlockBase.Text = headerButtonCaption; button.HeaderButtonTextBlockHighlight.Text = headerButtonCaption; var tooltip = ToolTipService.GetToolTip(button.ButtonControl) as ToolTip; if(tooltip != null) { tooltip.Content = headerButtonTooltip; } button.ButtonControl.Command = buttonCommand; button.SetValue(Grid.ColumnProperty, existingColCount); destinationGrid.Children.Add(button); }; timer.Start(); }