问题
How to display an Error or information (Toast,Message Box..) from view model to view.
Note: I am developing a cross platform application for Droid,Touch and Wp8.
回答1:
There are several ways to do this:
Use a messenger or a custom object/event chain to send the error event notification to the UI. This is shown in https://github.com/MvvmCross/MvvmCross-Tutorials/tree/master/Sample%20-%20BestSellers/BestSellers and discussed in Alerts or Popups in MvvmCross
Provide and use a "dialog service" - like that provided by https://github.com/brianchance/MvvmCross-UserInteraction - in order to show messages
Use an "interaction pattern" - like that exposed by Prism - see MvvmCross Dialog
回答2:
We've successfully tried to use the plugin 'Acr.MvvmCross.Plugins.UserDialogs' and it's working very well and has many features.
For example we have in splash screen a checking connectivity module and we used the plugin in order to display an error message:
public override void ReportError(string error)
{
InvokeOnMainThread(() =>
{
var toast = Mvx.Resolve<IUserDialogService>();
toast.Toast("Network error, please restart the application", 5);
});
}
BTW, if you're interested in other useful plugins have a look at this page: https://github.com/aritchie/acrmvvmcross
来源:https://stackoverflow.com/questions/19448898/display-error-or-information-from-viewmodel-to-view