Display Error or Information from ViewModel to View

廉价感情. 提交于 2019-12-11 06:48:33

问题


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:

  1. 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

  2. Provide and use a "dialog service" - like that provided by https://github.com/brianchance/MvvmCross-UserInteraction - in order to show messages

  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!