【问题标题】:WPF: Best way to raise a popup window that is modal to the page?WPF:提升页面模式的弹出窗口的最佳方法?
【发布时间】:2009-01-09 18:41:26
【问题描述】:

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

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

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

【问题讨论】:

标签: wpf popup


【解决方案1】:

这个StackOverflow answer 可以帮助你。 我创建了一些其他用户要求的示例代码。我已将此添加到博客文章 here

希望这会有所帮助!

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 这个想法是只阻止 UI 的某些部分(在本例中为页面)并让应用程序的其他部分继续工作。不阻止整个应用程序。
    • 院长,你做主。你的正是我想要的,一个真正的阻塞模式对话框。谢谢!
    • 太棒了!像魅力一样工作!
    【解决方案3】:

    您可以创建一个弹出类,使用装饰层将自己置于其他所有内容之上。

    为具有名为 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;
    }
    

    我希望这可以为您指明正确的方向。

    【讨论】:

    • 我知道这是可探索的选项,但正在寻找已经探索过这些选项并得出结论的人。还是谢谢!
    【解决方案4】:

    Windows 不希望您这样做 - 这不是 WPF 的事情。使用覆盖面板并使用 visible 或 zorder 属性。

    Wikipedia 讨论得很好。

    【讨论】:

    • 帮不上什么忙...我将不得不实施各种管理按键、点击等操作。
    • 同意。 Mac 和其他平台支持更精细的模式范围 - 但不支持 Windows。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多