首页 > 其他 > 详细

[原创]MvvmLight中用IDialogService替代DialogMessage的用法

时间:2014-10-20 08:38:39      阅读:930      评论:0      收藏:0      [点我收藏+]

在新版的MvvmLight中,DialogMessage被标注为已过时,需要用IDialogService来替代,IDialogService的具体用法如下:

先在主窗体中实现IDialogService :

public partial class MainWindow : Window, IDialogService

        public System.Threading.Tasks.Task ShowError(Exception error, string title, string buttonText, Action afterHideCallback)         {             throw new NotImplementedException();         }

        public System.Threading.Tasks.Task ShowError(string message, string title, string buttonText, Action afterHideCallback)         {             throw new NotImplementedException();         }
        public System.Threading.Tasks.Task<bool> ShowMessage(string message, string title, string buttonConfirmText, string buttonCancelText, Action<bool> afterHideCallback)         {             throw new NotImplementedException();         }
        public System.Threading.Tasks.Task ShowMessage(string message, string title, string buttonText, Action afterHideCallback)         {             throw new NotImplementedException();         }
        public System.Threading.Tasks.Task ShowMessage(string message, string title)         {             //throw new NotImplementedException();             MessageBox.Show(message, title);             return null;         }
        public System.Threading.Tasks.Task ShowMessageBox(string message, string title)         {             //throw new NotImplementedException();             MessageBox.Show(message, title);             return null;         }
然后在其它窗体中登记IDialogService:
        public IDialogService DialogService
        {
             get
            {
                return ServiceLocator.Current.GetInstance<IDialogService>();
            }
        }
使用时即为:
DialogService.ShowMessageBox("请输入名称!", "提示");

[原创]MvvmLight中用IDialogService替代DialogMessage的用法

原文:http://www.cnblogs.com/pzwsoft/p/4036393.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!