简体   繁体   English

即使鼠标处于锁定状态,WPF Grid也不触发不可见的鼠标事件

[英]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. 在我的WPF应用程序中,我有一个带有MouseDown,MouseUp和MouseMove事件的网格。 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). 问题是,当网格不可见时(Visibility.Hidden),我没有任何鼠标事件。

This is the MouseDown handler: 这是MouseDown处理程序:

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

And the MouseUp handler: 和MouseUp处理程序:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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