Handle the ToolTip logic globally

2 posts, 0 answers
  1. Janko
    Janko avatar
    6 posts
    Member since:
    Sep 2012

    Posted 06 Jun Link to this post

    I want to handle the tooltip logic globally for all UIElements of my RadWindow.
    More precisely, the UIElement under the mouse pointer should be used to decide what ToolTip content is shown and whether the Tooltip is shown.

    Is that possible by using e.g. RadToolTip/ RadToolTipService/ ToolTip or do I need something else?

    ----


    If it is unclear what I mean, here is a similar behaviour I've already implemented. However it is used for the RadContextMenu instead of a tool tips.
     (i.e. the clicked UIElement is used to decide what Context Menu is shown and whether the context Menu is shown.)


            // this xaml is somewhere very high in the visual tree and therefore handles all children of that node
            <telerik:RadContextMenu.ContextMenu>
                <telerik:RadContextMenu x:Name="MyContextMenu" Opening="RadContextMenu_Opening">
                    <telerik:RadMenuItem x:Name="Item1" Header="Item1"/>
                    <telerik:RadMenuItem x:Name="Item2" Header="Item2"/>
                    <telerik:RadMenuItem x:Name="Item3" Header="Item3"/>
                </telerik:RadContextMenu>
            </telerik:RadContextMenu.ContextMenu>



            private void RadContextMenu_Opening(object sender, Telerik.Windows.RadRoutedEventArgs e)
            {
                e.Handled = true; // do not show context menu except if I say otherwise further below

                var source = MyContextMenu.GetClickedElement<FrameworkElement>();
                if (source == null)
                    return;
                var itemToShowContextMenuFor = GetViewModelFromBestParentInVisualTreeOrNull(source)
                if (itemToShowContextMenuFor == null)
                    return;

                // e.g. set visibility for each RadMenuItem
                SetContextMenuItems(itemToShowContextMenuFor, out var showContextMenu)

                if (showContextMenu)
                    e.Handled = false; // show context menu
            }
  2. Martin Ivanov
    Admin
    Martin Ivanov avatar
    2090 posts

    Posted 07 Jun Link to this post

    Hello Janko,

    The tooltips in the WPF framework appear when you mouse enter the corresponding element. This means that there is no convenient approach (like with the context menu) to define a global tooltip on the root UI element because you are always in mouse over state of the element. 

    The most convenient approach would be to manually set the RadToolTipService.ToolTipContent or the native ToolTip property of the elements that should display a tooltip. 

    Regards,
    Martin Ivanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top