【问题标题】:Hosting a modal dialog in a ContentControl在 ContentControl 中托管模式对话框
【发布时间】:2012-02-07 02:08:29
【问题描述】:

我不想将我的模式对话框托管在我的主窗口的中心,而是将它托管在我的主窗口中的一个 ContentControl 中。希望有人可以建议我如何去做。谢谢。

【问题讨论】:

  • “模态对话框”是什么意思?举个例子。

标签: wpf dialog hosting


【解决方案1】:

我在github 上有一个自定义FrameworkElement 的示例,它允许您在主要内容上显示模态内容。

控件可以这样使用:

<c:ModalContentPresenter IsModal="{Binding DialogIsVisible}">
    <TabControl Margin="5">
            <Button Margin="55"
                    Padding="10"
                    Command="{Binding ShowModalContentCommand}">
                This is the primary Content
            </Button>
        </TabItem>
    </TabControl>

    <c:ModalContentPresenter.ModalContent>
        <Button Margin="75"
                Padding="50"
                Command="{Binding HideModalContentCommand}">
            This is the modal content
        </Button>
    </c:ModalContentPresenter.ModalContent>

</c:ModalContentPresenter>

特点:

  • 显示任意内容。
  • 在显示模式内容时不禁用主要内容。
  • 在显示模式内容时禁用鼠标和键盘访问主要内容。
  • 仅适用于它所覆盖的内容,而不是整个应用程序。
  • 可以通过绑定到IsModal 属性以对MVVM 友好的方式使用。

【讨论】:

    【解决方案2】:

    我有一个自定义的UserControl 来完成这个行为。有代码的文章找到here,可以这样使用:

    <local:PopupPanel 
        Content="{Binding PopupContent}"
        local:PopupPanel.PopupParent="{Binding ElementName=PopupParentPanel}"
        local:PopupPanel.IsPopupVisible="{Binding IsPopupVisible}" />
    

    【讨论】:

    • 非常感谢,瑞秋... :)
    猜你喜欢
    • 1970-01-01
    • 2015-04-15
    • 1970-01-01
    • 1970-01-01
    • 2015-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多