-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDialogsViewModel.cs
90 lines (69 loc) · 3.18 KB
/
DialogsViewModel.cs
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
90
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using MaterialDesignThemes.Wpf;
namespace SpecWpfMash
{
public class DialogsViewModel : INotifyPropertyChanged
{
//public ICommand ExampleDialogCommand { get; }
public DialogsViewModel()
{
}
//public ICommand RunDialogCommand => new AnotherCommandImplementation(ExecuteRunDialog);
public ICommand ShowLoginDialogCommand => new AnotherCommandImplementation(ShowLoginDialog);
public ICommand ExampleDialogCommand => new AnotherCommandImplementation(ExampleDialog);
private async void ShowLoginDialog(object o)
{
//let's set up a little MVVM, cos that's what the cool kids are doing:
var view = new LoginDialog
{
DataContext = new LoginDialogViewModel()
};
//show the dialog
var result = await DialogHost.Show(view, "RootDialog", ExtendedOpenedEventHandler, ExtendedClosingEventHandler);
//check the result...
Console.WriteLine("Dialog was closed, the CommandParameter used to close it was: " + (result ?? "NULL"));
}
private void ExtendedOpenedEventHandler(object sender, DialogOpenedEventArgs eventargs)
{
Console.WriteLine("You could intercept the open and affect the dialog using eventArgs.Session.");
}
private void ExtendedClosingEventHandler(object sender, DialogClosingEventArgs eventArgs)
{
if ((bool)eventArgs.Parameter == false) return;
//OK, lets cancel the close...
eventArgs.Cancel();
//...now, lets update the "session" with some new content!
//eventArgs.Session.UpdateContent(new SampleProgressDialog());
//note, you can also grab the session when the dialog opens via the DialogOpenedEventHandler
//lets run a fake operation for 3 seconds then close this baby.
Task.Delay(TimeSpan.FromSeconds(3))
.ContinueWith((t, _) => eventArgs.Session.Close(false), null,
TaskScheduler.FromCurrentSynchronizationContext());
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private async void ExampleDialog(object o)
{
//let's set up a little MVVM, cos that's what the cool kids are doing:
var view = new ExampleDialog
{
//DataContext = new LoginDialogViewModel()
};
//show the dialog
var result = await DialogHost.Show(view, "RootDialog", ExtendedOpenedEventHandler, ExtendedClosingEventHandler);
//check the result...
Console.WriteLine("Dialog was closed, the CommandParameter used to close it was: " + (result ?? "NULL"));
}
// Make Handlers
}
}