这里的主要问题是如何以 MVVM 友好的方式显示搜索弹出窗口。我的github 帐户上有一个为此目的而设计的自定义控件的示例(完整的源代码可供下载)。
该控件可以这样使用:
<c:ModalContentPresenter IsModal="{Binding DialogIsVisible}">
<!-- This is the main content e.g. your maintenance screen -->
<TabControl Margin="5">
<Button Margin="55"
Padding="10"
Command="{Binding ShowModalContentCommand}">
This is the primary Content
</Button>
</TabItem>
</TabControl>
<c:ModalContentPresenter.ModalContent>
<!-- This is the modal content e.g. your search popup -->
<Button Margin="75"
Padding="50"
Command="{Binding HideModalContentCommand}">
This is the modal content
</Button>
</c:ModalContentPresenter.ModalContent>
</c:ModalContentPresenter>
模态内容直接显示在主要内容上(在您的情况下为维护屏幕),其可见性由IsModal
可以绑定到 viewModel 中的属性的属性控制。该属性将由搜索命令设置为 true,并且您的搜索网格将显示在维护屏幕的前面。
您的搜索屏幕“视图”将有一个关闭按钮,该按钮绑定到另一个 ICommand 对象,该对象只是将属性设置为 false 并隐藏弹出内容。
请注意,无需“传递”任何信息,因为主要内容和模态内容都由同一控件管理,因此它们共享相同的DataContext
内容,在您的情况下,这将是对您的 viewModel 的引用。