ContextMenu doesn't display Tooltips of ribbon commands

Ribbon for WPF Forum

Posted 12 years ago by Martin - Blaise - Statistics Netherlands
Version: 11.2.0551
Avatar
I have an inherited TreeView with a contextmenu of type ribbon:ContextMenu, containing ribbon:buttons. On viewing, these items display correctly, except in displaying the tooltip of the commands.

<bcontrols:SolutionExplorer x:Name="SolutionExplorerMain">
    <TreeView.ContextMenu>
        <ribbon:ContextMenu  >
                <ribbon:Button Command="ide:ApplicationCommands.ShowItemFolder" />
         </ribbon:ContextMenu> 
    </TreeView.ContextMenu>
</bcontrols:SolutionExplorer>
The commands are nicely filled and executed using the Actipro ribbon commands. Only no ScreenDescription is visible.

Any thoughts?

Comments (4)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Martin,

I believe that when in a menu, buttons won't show a screen tip unless at least one of the screentip properties is set on the control itself. If you only have them set on the command, it won't get picked up by default.

If you need to change that behavior, you can probably override this method on the button and don't call the base method if the button's Context is MenuItem.
protected override void OnScreenTipOpening(RoutedEventArgs e) { ... }


Actipro Software Support

Posted 12 years ago by Martin - Blaise - Statistics Netherlands
Avatar
Hi

After some fidling i found that OnScreenTipOpening never was called, nor was OnDataContextChanged. I decided to override OnCommandChanged in my own ContextButton:
    public class ContextButton : ActiproSoftware.Windows.Controls.Ribbon.Controls.Button {

        protected override bool CanUpdateCanExecuteWhenHidden {
            get {
                return true;
            }
        }

        protected override void OnCommandChanged(System.Windows.Input.ICommand oldCommand, System.Windows.Input.ICommand newCommand) {
            base.OnCommandChanged(oldCommand, newCommand);
            var comm = newCommand as ActiproSoftware.Windows.Controls.Ribbon.Input.RibbonCommand;
            if (comm != null) {
                ToolTip = comm.ScreenTipDescription;
            }
        }
    
    }
This solved the problem. Still strange that the base method doesn't do this for me, or maybe it is common that menu items don't have tooltips.
Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Martin,

Correct, menu items typically don't have tooltips. If we allowed them to be driven by commands by default, then anytime someone used common ones like ApplicationCommands.Open, etc. there would be an "Open" tooltip on the menu. That wouldn't look good so is why we don't show them by default.


Actipro Software Support

Posted 12 years ago by Martin - Blaise - Statistics Netherlands
Avatar
I ended up with this, a ContextButton that optionally collapses and shows a Tooltip:
   public class ContextButton : ActiproSoftware.Windows.Controls.Ribbon.Controls.Button {

        public static readonly DependencyProperty IsTooltipDisplayedProperty = DependencyProperty.Register("IsTooltipDisplayed", typeof(bool), typeof(ContextButton), new UIPropertyMetadata(false, IsToolTipDisplayedCallBack));
        public static readonly DependencyProperty IsHiddenWhenDisabledProperty = DependencyProperty.Register("IsHiddenWhenDisabled", typeof(bool), typeof(ContextButton), new UIPropertyMetadata(true));

        [DefaultValue(false)]
        public bool IsTooltipDisplayed {
            get { return (bool)GetValue(IsTooltipDisplayedProperty); }
            set { SetValue(IsTooltipDisplayedProperty, value); }
        }

        [DefaultValue(true)]
        public bool IsHiddenWhenDisabled {
            get { return (bool)GetValue(IsHiddenWhenDisabledProperty); }
            set { SetValue(IsHiddenWhenDisabledProperty, value); }
        }

        protected override bool CanUpdateCanExecuteWhenHidden {
            get {
                return true;
            }
        }

        protected override void OnCommandChanged(System.Windows.Input.ICommand oldCommand, System.Windows.Input.ICommand newCommand) {
            base.OnCommandChanged(oldCommand, newCommand);
            SetTooltip(IsTooltipDisplayed);
        }

        private void SetTooltip(bool tooltipOn) {
            if (tooltipOn) {
                var comm = this.Command as ActiproSoftware.Windows.Controls.Ribbon.Input.RibbonCommand;
                if (comm != null) {
                    ToolTip = comm.ScreenTipDescription;
                }
            } else {
                ToolTip = null;
            }
        }

        private static void IsToolTipDisplayedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e) {
            var b = d as ContextButton;
            b.SetTooltip((bool)e.NewValue);
        }

        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) {
            base.OnPropertyChanged(e);
            if (e.Property.Name == "IsEnabled" ||
                e.Property.Name == "IsHiddenWhenDisabled") {
                SetVisibility();
            }
        }

        private void SetVisibility() {
            if (this.IsEnabled) {
                this.Visibility = System.Windows.Visibility.Visible;
            } else
                if (this.IsHiddenWhenDisabled) {
                    this.Visibility = System.Windows.Visibility.Collapsed;
                } else {
                    this.Visibility = System.Windows.Visibility.Visible;
                }
        }




        
    }
The latest build of this product (v24.1.1) was released 22 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.