简体   繁体   English

WinRT中的对话框服务/ MVVM体系结构中的自定义模式对话框

[英]Dialog service in WinRT / custom modal dialog in MVVM architecture

My app has a simple search screen. 我的应用程序有一个简单的搜索屏幕。 One of the parameters is "Radius" (as in distance from the user's current location). 参数之一是“半径”(如距用户当前位置的距离)。 The radius selector is bound to "Radius" property on the ViewModel. 半径选择器绑定到ViewModel上的“ Radius”属性。

The ViewModel is listening for changes on the Radius property and when it changes, if the user has not previously selected their location I would like to invoke a dialog service. ViewModel正在侦听Radius属性上的更改,当它更改时,如果用户以前未选择其位置,则我想调用对话框服务。

So I'd like the app to use MVVM Light's messenger service to listen for messages from the ViewModel and if it receives the message "selectlocation", it should show a "Location selector" UI as a modal dialog box. 因此,我希望该应用程序使用MVVM Light的Messenger服务来侦听ViewModel的消息,如果接收到消息“ selectlocation”,则它应将“位置选择器” UI显示为模式对话框。

This is easy with MessageDialog. 使用MessageDialog很容易。 Somehow it creates its UI and overlays it on top of whatever is on screen. 它以某种方式创建其UI并将其覆盖在屏幕上的任何内容之上。 How do I do the same? 我该怎么做? But with a totally bespoke modal dialog? 但是带有完全定制的模态对话框?

I could create a usercontrol and host that within the page and then have the page listen for the messages and then display the user control, however, I'd prefer it at a global level. 我可以创建一个用户控件并将其托管在页面中,然后让页面侦听消息,然后显示用户控件,但是,我希望在全局级别使用它。

In pseudocode, I'd like to have a Dialog Service that does this: 用伪代码,我想要一个执行此操作的对话框服务:

void SelectLocation(onSuccessCallback, onCancelCallback)
{
    Window.Current.ShowDialog(new LocationSelectorUserControl(onSuccessCallback, onCancelCallback));
{

Virtually the same as MessageDialog but with a custom UI. 几乎与MessageDialog相同,但具有自定义UI。

Is there any way to do this? 有什么办法吗?

Speaking abstractly, to provide something similar, you have to create a blank window, that: 抽象地说,要提供类似的内容,您必须创建一个空白窗口,该窗口:

  • Centers itself on screen 中心本身在屏幕上
  • Declares itself topmost 宣布自己为最高
  • Disables parent window until it is closed 禁用父窗口,直到关闭它
  • Implements specific ShowDialog method overload with the return value you want to obtain 使用要获取的返回值实现特定的ShowDialog方法重载

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM