private static void OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { // This is a workaround for the issue that BetweenShowDelay property does not // work as expected. Even though this property has been set to '0ms' on all of // the Ribbon controls with the expectation that ToolTips will always appear // after the InitialShowDelay, ToolTips show immediately without the // InitialShowDelay when moving between controls when ToolTips are already active. // Manually setting IsOpen to false upon detecting this scenario prevents the // quick show and always causes the system to wait for the InitialShowDelay to elapse. RibbonToolTip ribbonToolTip = (RibbonToolTip)d; UIElement placementTarget = ribbonToolTip.PlacementTarget; if (ribbonToolTip.IsOpen) { RibbonToolTipService.Current.CurrentToolTip = ribbonToolTip; if (placementTarget != null) { placementTarget.MouseLeave += new MouseEventHandler(ribbonToolTip.OnPlacementTargetMouseLeave); } } else { RibbonToolTipService.Current.CurrentToolTip = null; if (placementTarget != null) { placementTarget.MouseLeave -= new MouseEventHandler(ribbonToolTip.OnPlacementTargetMouseLeave); } } }
/// <summary> /// Property changed callback for tooltip footer properties. /// Sets the value of HasFooter property accordingly. /// </summary> private static void OnToolTipFooterPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { RibbonToolTip ribbonToolTip = (RibbonToolTip)d; ribbonToolTip.HasFooter = (!string.IsNullOrEmpty(ribbonToolTip.FooterTitle) || !string.IsNullOrEmpty(ribbonToolTip.FooterDescription) || ribbonToolTip.FooterImageSource != null); }
/// <summary> /// Property changed callback for tooltip PlacementTarget property. /// </summary> private static void OnPlacementTargetPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { RibbonToolTip ribbonToolTip = (RibbonToolTip)d; UIElement target = e.NewValue as UIElement; if (target == null) { ribbonToolTip.Ribbon = null; } else { ribbonToolTip.Ribbon = RibbonControlService.GetRibbon(target); } }
/// <summary> /// This CoerceValueCallback hack is used to determine whether the current PlacementTarget is within a RibbonGroup. /// </summary> private static object CoerceIsOpen(DependencyObject d, object value) { if ((bool)value) { RibbonToolTip toolTip = (RibbonToolTip)d; RibbonGroup ribbonGroup = null; UIElement placementTarget = toolTip.PlacementTarget; // Walk up the visual tree from the PlacementTarget to see if // it belongs to a RibbonGroup. DependencyObject element = placementTarget; while (element != null) { ribbonGroup = element as RibbonGroup; if (ribbonGroup != null) { break; } DependencyObject visualParent = VisualTreeHelper.GetParent(element); if (visualParent == null) { // This special check is for the case that the PlacementTarget is // within the Popup of a Collapsed RibbonGroup Popup popupParent = LogicalTreeHelper.GetParent(element) as Popup; if (popupParent != null) { ribbonGroup = popupParent.TemplatedParent as RibbonGroup; } break; } element = visualParent; } // A RibbonGroup is in the QAT is special. Its tooltip should show relative // to the mouse instead of under the Ribbon. All other control in the QAT // are automatically taken care of because they will not be recognized as // belonging to a RibbonGroup. bool isToolTipForRibbonGroup = ribbonGroup != null && (toolTip.PlacementTarget == ribbonGroup || (VisualTreeHelper.GetChildrenCount(ribbonGroup) > 0 && toolTip.PlacementTarget == VisualTreeHelper.GetChild(ribbonGroup, 0))); toolTip.IsPlacementTargetInRibbonGroup = (ribbonGroup != null && (!isToolTipForRibbonGroup || !ribbonGroup.IsInQuickAccessToolBar)); } return(value); }
/// <summary> /// Initialize Automation Peer for RibbonToolTip /// </summary> public RibbonToolTipAutomationPeer(RibbonToolTip owner) : base(owner) { }
/// <summary> /// Sets ToolTip on the first Visual child of a FrameworkElement. /// </summary> /// <param name="element"></param> /// <param name="visualChild">First visual child of control</param> /// <param name="content">content to be set as ToolTip</param> /// <param name="value">Set or Unset ToolTip</param> public static void SetContentAsToolTip(FrameworkElement element, FrameworkElement visualChild, object content, bool value) { if (visualChild != null) { // Checks if ToolTip is not already set on the element if (value && element.ToolTip == null && content != null) { RibbonToolTip ribbonToolTip = visualChild.ToolTip as RibbonToolTip; if (ribbonToolTip == null || ribbonToolTip.Title != content.ToString()) { ribbonToolTip = new RibbonToolTip(); ribbonToolTip.Title = content.ToString(); visualChild.ToolTip = ribbonToolTip; } } else { visualChild.ToolTip = null; } } }
/// <summary> /// Helper method which serves as the coercion callback for /// ToolTip property of ribbon controls. It creates and updates a RibbonToolTip /// if needed and if possible and returns that as the coerced value. /// </summary> public static object CoerceRibbonToolTip(DependencyObject d, object value) { if (value == null) { string toolTipTitle = RibbonControlService.GetToolTipTitle(d); string toolTipDescription = RibbonControlService.GetToolTipDescription(d); ImageSource toolTipImageSource = RibbonControlService.GetToolTipImageSource(d); string toolTipFooterTitle = RibbonControlService.GetToolTipFooterTitle(d); string toolTipFooterDescription = RibbonControlService.GetToolTipFooterDescription(d); ImageSource toolTipFooterImageSource = RibbonControlService.GetToolTipFooterImageSource(d); if (!string.IsNullOrEmpty(toolTipTitle) || !string.IsNullOrEmpty(toolTipDescription) || toolTipImageSource != null || !string.IsNullOrEmpty(toolTipFooterTitle) || !string.IsNullOrEmpty(toolTipFooterDescription) || toolTipFooterImageSource != null) { RibbonToolTip ribbonToolTip = new RibbonToolTip(); ribbonToolTip.Title = toolTipTitle; ribbonToolTip.Description = toolTipDescription; ribbonToolTip.ImageSource = toolTipImageSource; ribbonToolTip.FooterTitle = toolTipFooterTitle; ribbonToolTip.FooterDescription = toolTipFooterDescription; ribbonToolTip.FooterImageSource = toolTipFooterImageSource; value = ribbonToolTip; } } return value; }