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

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

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

有帮助吗?

解决方案

StackOverflow答案可以帮助您。 我创建了一些其他用户要求的示例代码。我已将此添加到博客文章此处

希望这有帮助!

其他提示

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

http://www.deanchalk.com / WPF模态的控件-通dispatcherframe嵌套消息泵/

你可以创建一个弹出类,使用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;
}

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

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

维基百科有一个很好的讨论。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top