-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathDialogDemoViewModel.cs
More file actions
89 lines (77 loc) · 2.51 KB
/
DialogDemoViewModel.cs
File metadata and controls
89 lines (77 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System.Windows;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
#if !NET40
using System.Threading.Tasks;
#endif
using HandyControl.Controls;
using HandyControl.Tools.Extension;
using HandyControlDemo.Data;
using HandyControlDemo.UserControl;
using HandyControlDemo.Window;
namespace HandyControlDemo.ViewModel;
public class DialogDemoViewModel : ViewModelBase
{
private string _dialogResult;
public string DialogResult
{
get => _dialogResult;
#if NET40
set => Set(nameof(DialogResult), ref _dialogResult, value);
#else
set => Set(ref _dialogResult, value);
#endif
}
public RelayCommand<FrameworkElement> ShowTextCmd => new(ShowText);
private void ShowText(FrameworkElement element)
{
if (element == null)
{
Dialog.Show(new TextDialog());
}
else
{
Dialog.Show(new TextDialog(), MessageToken.DialogContainer);
}
}
#if NET40
public RelayCommand<bool> ShowInteractiveDialogCmd => new(ShowInteractiveDialog);
private void ShowInteractiveDialog(bool withTimer)
{
if (!withTimer)
{
Dialog.Show<InteractiveDialog>()
.Initialize<InteractiveDialogViewModel>(vm => vm.Message = DialogResult)
.GetResultAsync<string>().ContinueWith(str => DialogResult = str.Result);
}
else
{
Dialog.Show<TextDialogWithTimer>(MessageToken.MainWindow).GetResultAsync<string>();
}
}
#else
public RelayCommand<bool> ShowInteractiveDialogCmd => new(async withTimer => await ShowInteractiveDialog(withTimer));
private async Task ShowInteractiveDialog(bool withTimer)
{
if (!withTimer)
{
DialogResult = await Dialog.Show<InteractiveDialog>()
.Initialize<InteractiveDialogViewModel>(vm => vm.Message = DialogResult)
.GetResultAsync<string>();
}
else
{
await Dialog.Show<TextDialogWithTimer>(MessageToken.MainWindow).GetResultAsync<string>();
}
}
#endif
public RelayCommand NewWindowCmd => new(() => new DialogDemoWindow
{
Owner = Application.Current.MainWindow
}.Show());
public RelayCommand<string> ShowWithTokenCmd => new(token => Dialog.Show(new TextDialog(), token));
public RelayCommand<string> CloseMainWindowDialogCmd => new(Dialog.Close);
public RelayCommand DragDialogCmd => new(() => {
Dialog.Show(new DragDialogDemo(), MessageToken.MainWindow);
});
}