WPF 网格在不可见时不会触发鼠标事件,即使鼠标已被捕获

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

在我的 WPF 应用程序中,我有一个带有 MouseDown、MouseUp 和 MouseMove 事件的网格。我希望网格在我按下鼠标左键时消失,并在我释放它时重新出现。问题是当网格不可见时我没有收到任何鼠标事件 (Visibility.Hidden)。

这是 MouseDown 处理程序:

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

和 MouseUp 处理程序:

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

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