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


    在新版的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("请输入名称!", "提示");
  • 相关阅读:
    JDBC-HikariCP
    11、JDBC-Druid
    JDBC-DBCP
    JDBC-C3P0
    第十七篇-使用RadioGroup实现单项选择
    第十六篇-使用CheckBox实现多项选择
    第一篇-ubuntu18.04访问共享文件夹
    第十五篇-EditText做简单的登录框
    第十四篇-ImageButton控制聚焦,单击,常态三种状态的显示背景
    第十三篇-通过Button设置文本背景颜色
  • 原文地址:https://www.cnblogs.com/pzwsoft/p/4036393.html
Copyright © 2020-2023  润新知