简体   繁体   中英

WPF Grid doesn't fire mouse events when invisible, even though the mouse is capured

In my WPF application I have a Grid with MouseDown, MouseUp and MouseMove events. I want the grid to disappear whenever I press the left mouse button, and reappear when I release it. The problem is that I don't get any mouse events while the grid is invisible (Visibility.Hidden).

This is the MouseDown handler:

private void TabHeaderOnMouseDown(object sender, MouseButtonEventArgs e)
{
    tabHeader.CaptureMouse();
    tabHeader.Visibility = Visibility.Hidden;
}

And the MouseUp handler:

private void TabHeaderOnMouseUp(object sender, MouseButtonEventArgs e)
{
    tabHeader.ReleaseMouseCapture();
    tabHeader.Visibility = Visibility.Visible;
}

将不透明度设置为0而不是更改可见性解决了我的问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM