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
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!!
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;
}
Don't set the IsHitTestVisible="False"
!
Just add those lines
IsEnable = false
ToolTipService.ShowOnDisabled="True"
精彩评论