/// <summary> /// 登陆入口 获取用户名密码执行之后操作 /// </summary> /// <param name="obj"></param> private async void ExecuteRunLogin(object obj) { if (!TestInput()) { return; } //Whiting dialog var view = new WitingDialog() { ButtonCancle = { Visibility = Visibility.Collapsed } }; //show the dialog var result = await DialogHost.Show(view, "RootDialog", AddMemberDialogOpeningEventHandler); //check the result... Console.WriteLine("Dialog was closed, the CommandParameter used to close it was: " + (result ?? "NULL")); if (result != null && (bool)result) { LoginSuccess(obj); } }
/// <summary> /// Search operation history /// </summary> /// <param name="o"></param> private async void ExecuteRunSearch(object o) { if (startTimeTime != null && endTimeTime != null && startTimeDate != null && endTimeDate != null) { if (startTimeDate <= endTimeDate) { if (!(startTimeDate == endTimeDate && startTimeTime > endTimeTime)) { ///do some thing var view = new WitingDialog(); //show the dialog var result = await DialogHost.Show(view, "RootDialog", Search_DialogHost_OnDialogOpening, Search_DialogHost_OnDialogClosing); //check the result... Console.WriteLine("Dialog was closed, the CommandParameter used to close it was: " + (result ?? "NULL")); return; } } } //let's set up a little MVVM, cos that's what the cool kids are doing: var view1 = new SimpleMessageDialog { Message = { Text = "开始时间不能晚于结束时间!", TextAlignment = TextAlignment.Center }, CancelButton = { Visibility = Visibility.Collapsed } }; //show the dialog var result1 = await DialogHost.Show(view1, "RootDialog"); //check the result... Console.WriteLine("Dialog was closed, the CommandParameter used to close it was: " + (result1 ?? "NULL")); }
/// <summary> /// Do some task whith one input and output, it will use some time, /// so get the whiting dialog when task is running, when finished will have a message dialog. /// Of couse you can output one object via CommandParameter. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="task"></param> /// <param name="obj"></param> /// <returns></returns> private async Task <bool> DoAsyncTask <T>(Func <T, dynamic> task, T obj) { var viewWiting = new WitingDialog { ButtonCancle = { Visibility = Visibility.Collapsed } }; var viewMessage = new SimpleMessageDialog(); DialogHost.Show(viewWiting, "RootDialog"); dynamic r = null; await Task.Run(() => { r = task(obj); }).ContinueWith(async(t, o) => { viewMessage = new SimpleMessageDialog { Message = { Text = r.State == 1 ? " 操作成功! \r\n" + r.Msg.Result : "操作失败!\r\n" + (string.IsNullOrEmpty(r.Msg.Result) ? "没有错误提示" : r.Msg.Result) }, CancelButton = { Visibility = Visibility.Collapsed }, Icon = { Kind = r.State == 1 ? PackIconKind.CheckCircleOutline : PackIconKind.AlertCircleOutline }, OkButton = { CommandParameter = r.State == 1 } }; }, null, TaskScheduler.FromCurrentSynchronizationContext()); if (r.State == 1) { await UpdateDatacontext(); } viewWiting.ButtonCancle.Command.Execute(null); await DialogHost.Show(viewMessage, "RootDialog"); return(r.State == 1); }