Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XAML ToolTip + IsHitTestVisible="False"

We need to have mouse clicks and drags "ignored" by our View1 but the ToolTip must still function in that view. The reason is View1 is above View2 in Z-Order, so View1 can tint View2 a red color and show a warning via ToolTip; however the ToolTip accompanying View1 will not work if IsHitTestVisible="False".

Anyone know a work around so the ToolTip will display on mouse move/over and the rest of mouse events are ignored by View1 and go to View2?

Thanks,

Sean

like image 837
Sean B Avatar asked May 05 '10 14:05

Sean B


People also ask

What is IsHitTestVisible?

#680 – IsHitTestVisible Applies to All Child Elements If you set the IsHitTestVisible property of a container element to false, it will turn off hit testing for all elements within that container. Even if a child element sets its own IsHitTestVisible property to true, it will still be hidden from hit testing.

How do I set ToolTip location?

You can position a ToolTip by setting the PlacementTarget, PlacementRectangle, Placement, HorizontalOffset, and VerticalOffsetProperty properties. These properties behave the same as they do for a Popup.

What is ToolTip in XAML?

The ToolTip element in XAML adds a tooltip to a WPF control. The ToolTip class represents a tooltip in C#. The ToolTip property of a control represents the tool tip of the control. Code examples in this this article show how to attach Tooltips to WPF controls using C# and XAML. TooltipWPF.zip.


2 Answers

If someone else is facing same problem, they may find it helpful. We had a requirement to disable few rows on datagrid, but at the same time allow ARROW key navigation on them. This is why we had to switch to IsHitTestVisible instead of controlling IsEnabled property. So we couldn't adopt to above solution of switching to IsEnabled property.

Here is how I ended up solving this issue. I created a new attached property RowEnable for DataGridRow. This attached property can be bind to a viewmodel property to control virtual enable and disablement. I also created a new style for DataGridCell where I am setting IsHitTestVisible to false based on the same viewmodel property. So, consider it like a row which mouse/keyboard can see, but can't see its cells/columns. This means now I can style the row based on new attached property RowEnabled to look disabled/enabled. At the same time, I can take view tooltips for these tows which are virtually disabled.

Hope this helps!!

like image 155
Vipin Gupta Avatar answered Oct 14 '22 09:10

Vipin Gupta


What I did which is not great:

    private void UserControl_Loaded(object sender, RoutedEventArgs e)
    {
        var parentWindow = Window.GetWindow(this);
        var source = PresentationSource.FromVisual(parentWindow) as HwndSource;

        source.AddHook(WndProc);
    }

    private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        // Handle messages... 
        if (msg == WM_MOUSEMOVE)
        {
        ...show tool tip if mouse is over it
        }
        return IntPtr.Zero;
    }
like image 32
Sean B Avatar answered Oct 14 '22 10:10

Sean B