为了在 WPF 中模拟模式对话框,我显示一个窗口并调用:Mouse.Capture(dialogBoxArea, CaptureMode.SubTree);
调用返回false
。
Mouse.Captured
是null
。
dialogBoxArea.Visibility
是Visibility.Visible
。
dialogBoxArea.IsEnabled
是true
。
如果第二次再次调用该行,它将返回true
并正确捕获鼠标。
我可能缺少什么条件会阻止捕获工作?
编辑
这是我到目前为止所尝试的。
if (Mouse.Captured != null)
{
// Not called, so presumably, nothing has already captured the mouse
MessageBox.Show("already captured");
}
if (dialogBoxArea.Visibility != Visibility.Visible)
{
// Not called
MessageBox.Show("not visible");
}
if (!dialogBoxArea.IsEnabled)
{
// Not called
MessageBox.Show("not enabled");
}
// According to documentation, this should release mouse capture from anything that holds it
Mouse.Capture(null);
// Attempt to capture the mouse
if (!Mouse.Capture(dialogBox, CaptureMode.SubTree))
{
// This is called
Mouse.Capture(null);
Mouse.Capture(dialogBox, CaptureMode.SubTree);
}