在ContentControl中托管模态对话框 [英] Hosting a modal dialog in a ContentControl
本文介绍了在ContentControl中托管模态对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
而不是在我的MainWindow的中心托管我的模态对话框,我想在其MainWindow内的一个ContentControl中托管它。希望有人能告诉我如何去做这件事。谢谢。
Instead of hosting my modal dialog at the center of my MainWindow, I would like to host it within one of the ContentControls within my MainWindow. Hope someone can advise me how to go about this. Thanks.
推荐答案
我有一个例子,在 github 的自定义 FrameworkElement
,允许您在主要内容上显示模态内容。
I have an example on github of a custom FrameworkElement
that allows you to display modal content over the primary content.
控件可以这样使用:
<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友好的方式。
- Displays arbitrary content.
- Does not disable the primary content whilst the modal content is being displayed.
- Disables mouse and keyboard access to the primary content whilst the modal content is displayed.
- Is only modal to the content it is covering, not the entire application.
- can be used in an MVVM friendly way by binding to the
IsModal
property.
这篇关于在ContentControl中托管模态对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文