MvvmCross中的警报或弹出窗口 [英] Alerts or Popups in MvvmCross

查看:123
本文介绍了MvvmCross中的警报或弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MvvmCross是否支持用于显示警报或弹出窗口的跨平台解决方案?

Does MvvmCross support a cross platform solution for displaying alerts or popups?

搜索我找到的代码MvxDialogActivityView,但已将其注释掉.现在是否仍然如此?

Searching the code I found MvxDialogActivityView but it has been commented out. Will this remain the case for now?

如果没有直接支持,您如何建议最好做这件事? (也许ViewModel会更改属性并调用FirePropertyChanged,以便View能够意识到它并显示警报.)

If there is no direct support how would you suggest this is best done? (Perhaps the ViewModel would change a property and call FirePropertyChanged so that the View would be aware of it and show an alert.)

编辑2012年6月16日16:04

在这种情况下,我想做的事情如下: 在页面上单击一个按钮,这将导致一种方法在ViewModel中运行,该方法将进行评估以确定应向客户显示两条消息中的哪一条.该消息将显示为警报或弹出窗口(本机或最好由我完全设置样式).该消息将在(单击确定"按钮,最好是3秒钟)后消失.

What I am trying to do for this specific case is as follows: On the page a button is clicked, which causes a method to run in the ViewModel which does an evaluation to determine which of two messages should be shown to the customer. The message would be shown as an alert or popup (either native, or preferably totally styled by me). The message would fade after (the click of the OK button, or preferably 3 seconds).

信息被取消后,也会浏览一个新页面(取决于显示的是这两个信息中的哪一个).

After the message has been dismissed a new page will be navigated too (depending on which of the two messages was shown).

推荐答案

如何处理此问题完全取决于情况-没有最佳的单一规则(IMHO)

How to handle this definitely depends on what the situation is - there's no single best rule (IMHO)

对于一般的错误显示模式,请在中提出一项建议. http://slodge.blogspot.co.uk/2012/05/one-pattern-for-error-handling-in.html

For a general error display pattern, there's one proposal at http://slodge.blogspot.co.uk/2012/05/one-pattern-for-error-handling-in.html

我使用了类似的模式来显示应用程序级别的通知-例如用于长时间运行的操作何时完成或聊天消息何时到达或...

I've used similar patterns for showing application level notifications - e.g. for when a long running operation completes or when a chat message arrives or...

关于如何显示消息框的一篇有趣的帖子是: http://awkwardcoder.blogspot.co.uk/2012/03/showing-message-box-from-viewmodel-in.html -我不确定我是否会完全遵循最终解决方案,但是绝对有一些关于不该做的好点.

One interesting post about how to display message boxes was: http://awkwardcoder.blogspot.co.uk/2012/03/showing-message-box-from-viewmodel-in.html - I'm not sure I'd completely follow the end solution, but there are definitely some good points there about what not to do.

对于您的最新方案,我会考虑使用Messenger(例如TinyMessenger)或使用ViewModel公开并由其View消耗的普通C#事件.

For your updated scenario, I would consider using a messenger (like TinyMessenger) or using normal C# events exposed by the ViewModel and consumed by its View

在页面上单击一个按钮,这将导致方法在ViewModel中运行

On the page a button is clicked, which causes a method to run in the ViewModel

我将使用绑定到按钮Click/Tap/TouchDown的ICommand来实现此功能

I would implement this using an ICommand bound to the button Click/Tap/TouchDown

进行评估以确定应该向客户显示两个消息中的哪一个.

which does an evaluation to determine which of two messages should be shown to the customer.

我肯定会在服务中实现逻辑

I would definitely implement the logic within a Service

这将从ViewModel中调用-结果/决定可能会导致某些属性或私有字段状态更改.

This would be called from the ViewModel - and the result/decision would probably cause some property or private field state change.

视图如何决定显示一条消息?我可以想到3种选择:

How does the View then decide to show a message? I can think of 3 options:

  1. 视图仅可以响应属性更改(普通Mvvm INPC)-这是我的偏好
  2. ViewModel可能会公开一个普通的C#事件,它会触发...
  3. ViewModel可以发送消息

最后一个选项(Messenging)可能是这里最灵活的解决方案-它分离了View和ViewModel,以防您稍后决定更改职责.要实施Messenger,可以:

This last option (Messenging) is probably the most flexible solution here - it decouples the View and ViewModel in case you later decide to change responsibilities. To implement messenging, either:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆