Merge pull request #58 from DingpingZhang/enhance-dialog

添加“Dialog.ShowAsync<T>(): T”函数以获得Dialog的返回值
This commit is contained in:
NaBian authored and GitHub committed 2019-04-03 22:08:22 +08:00
commit d26e29176d
13 files changed
+395 -161

No files matched your search

@@ -0,0 +1,30 @@
using System;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;
using HandyControl.Tools.Extension;
namespace HandyControlDemo.ViewModel.Basic
{
public class InteractiveDialogViewModel : ViewModelBase, IDialogResultable<string>
{
public Action CloseAction { get; set; }
private string _result;
public string Result
{
get => _result;
set => Set(ref _result, value);
}
private string _message;
public string Message
{
get => _message;
set => Set(ref _message, value);
}
public RelayCommand CloseCmd => new Lazy<RelayCommand>(() => new RelayCommand(() => CloseAction?.Invoke())).Value;
}
}
@@ -1,13 +1,25 @@
using System;
using System.Threading.Tasks;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;
using HandyControl.Controls;
using HandyControl.Tools.Extension;
using HandyControlDemo.UserControl;
using HandyControlDemo.UserControl.Basic;
using HandyControlDemo.ViewModel.Basic;
namespace HandyControlDemo.ViewModel
{
public class DialogDemoViewModel : ViewModelBase
{
private string _dialogResult;
public string DialogResult
{
get => _dialogResult;
set => Set(ref _dialogResult, value);
}
public RelayCommand ShowTextCmd => new Lazy<RelayCommand>(() =>
new RelayCommand(ShowText)).Value;
@@ -15,5 +27,15 @@ namespace HandyControlDemo.ViewModel
{
Dialog.Show(new TextDialog());
}
public RelayCommand ShowInteractiveDialogCmd => new Lazy<RelayCommand>(() =>
new RelayCommand(async () => await ShowInteractiveDialog())).Value;
private async Task ShowInteractiveDialog()
{
DialogResult = await Dialog.Show<InteractiveDialog>()
.Initialize<InteractiveDialogViewModel>(vm => vm.Message = DialogResult)
.GetResultAsync<string>();
}
}
}
@@ -1,10 +1,10 @@
using System;
using System.Reflection.Emit;
using System.Windows;
using CommonServiceLocator;
using GalaSoft.MvvmLight.Ioc;
using HandyControlDemo.Data;
using HandyControlDemo.Service;
using HandyControlDemo.ViewModel.Basic;
namespace HandyControlDemo.ViewModel
{
@@ -30,6 +30,7 @@ namespace HandyControlDemo.ViewModel
SimpleIoc.Default.Register<DialogDemoViewModel>();
SimpleIoc.Default.Register<SearchBarDemoViewModel>();
SimpleIoc.Default.Register<NotifyIconDemoViewModel>();
SimpleIoc.Default.Register<InteractiveDialogViewModel>();
}
public static ViewModelLocator Instance => new Lazy<ViewModelLocator>(() =>
@@ -65,6 +66,7 @@ namespace HandyControlDemo.ViewModel
public NotifyIconDemoViewModel NotifyIconDemo => ServiceLocator.Current.GetInstance<NotifyIconDemoViewModel>();
public InteractiveDialogViewModel InteractiveDialog => ServiceLocator.Current.GetInstance<InteractiveDialogViewModel>();
#endregion
}
}