【问题标题】:WPF Grid doesn't fire mouse events when invisible, even though the mouse is capuredWPF Grid 在不可见时不会触发鼠标事件,即使鼠标被捕获
【发布时间】:2018-04-09 19:33:02
【问题描述】:

在我的 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;
}

【问题讨论】:

  • 改为设置Opacity = 0

标签: c# wpf grid mouseevent hidden


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-04-04
    • 2013-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多