WPF:提出一个模态页面的弹出窗口的最佳方法?

时间:2009-01-09 18:41:26

标签: wpf popup

我正在使用导航样式页面而不是窗口构建WPF应用程序。 我想在页面内显示一个窗口,这个窗口必须是页面的模态,但是允许用户转到其他页面,并返回到同一状态的模态窗口的同一页面。

我尝试过使用WPF弹出控件,但问题是每次离开页面时控件都会隐藏。我想我可以编写代码再次显示它,但不会以正确的方式接缝。

在WPF中执行此操作的最佳方法是什么?

4 个答案:

答案 0 :(得分:17)

StackOverflow answer可能会帮助您。 我创建了一些其他用户要求的示例代码。我已将此添加到博文here

希望这有帮助!

答案 1 :(得分:5)

为什么不使用嵌套的消息泵来创建模态控件

http://www.deanchalk.com/wpf-modal-controls-via-dispatcherframe-nested-message-pumps/

答案 2 :(得分:3)

你可以创建一个弹出类,使用adorner层将自己放在其他所有东西上。

为具有名为 IsOpen 属性的弹出窗口创建基类,并在更改时将控件可见性设置为适当的值。

要停止单击弹出窗口下方的控件,可以弹出页面的完整大小。除了弹出窗口的实际中间部分外,你会发现它大部分都是透明的。如果你想让弹出窗口完全透明,你需要在弹出窗口中覆盖HitTestCore。

这样的事情:

protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters)
{
    // We want this control to behaive as a single rectangle and we don't much care
    // whether or it has a solid background.  So we override this method so we can have    // mouse over info for the entire panel regardless of background.

    // run the base hit test first, because if it finds something we don't want to overrule it.
    HitTestResult result = base.HitTestCore(hitTestParameters);


    // If we didn't get a hit generate a new hit test result, because HitTestCore is never called unless
    // the mouse is over the controls bounding rectangle.
    if (result == null)
        result = new PointHitTestResult(this, hitTestParameters.HitPoint);

    return result;
}

我希望这可以指出你正确的方向。

答案 3 :(得分:1)

Windows不喜欢你这样做 - 它不是WPF的东西。使用覆盖面板并使用visible或zorder属性。

Wikipedia有一个很好的讨论。