本文介绍了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

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

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

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

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:

这是一个与View有关的问题-因此将完全由View项目控制.我会使用以下控件:UIAlert,Toast,ToastPrompt等-所有这些都可以设置样式

This is a View concern - so would be entirely controlled by the View project. I'd use controls like: UIAlert, Toast, ToastPrompt, etc - all of which can be styled

我会在视图中使用某种形式的代码隐藏(或WP7中的行为).这将检测到单击/淡入/消失,然后在ViewModel上调用ICommand(我的偏好)或public方法

I'd use some form of Code Behind (or maybe a Behaviour in WP7) in the View. This would detect the click/fade/disappear and would then invoke either an ICommand (my preference) or public method on the ViewModel

需要从ViewModel请求此导航

This navigation would be requested from the ViewModel

这很容易跟踪上述流程...大概是ViewModel已经知道要显示什么.

This would be easy to track through the above flow... presumably the ViewModel already knows what to show.

这就是我要做的...

So that's what I'd do...

...但是我确定还有其他选择:)

...but I'm sure there are other options :)

最后一点...通过在WP7和Android上切换/启用墓碑功能,淡出然后导航的逻辑确实可以被弄乱"-这可能与您的特定情况无关紧要.

One final note... the fade out and then navigate logic can really get "messed up" by Switching/Tombstoning on WP7 and Android - this may or may not matter for your particular scenario.

这篇关于MvvmCross中的警报或弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!