-
Notifications
You must be signed in to change notification settings - Fork 9
/
MainWindowViewModel.cs
44 lines (36 loc) · 1.11 KB
/
MainWindowViewModel.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
using System.ComponentModel;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using HanumanInstitute.MvvmDialogs;
namespace Demo.Wpf.ViewEvents;
public class MainWindowViewModel : ObservableObject, IViewLoaded, IViewClosing, IViewClosed
{
private readonly IDialogService _dialogService;
public MainWindowViewModel(IDialogService dialogService)
{
this._dialogService = dialogService;
}
public string Text
{
get => _text;
set => this.SetProperty(ref _text, value);
}
private string _text = string.Empty;
public void OnClosed()
{
_dialogService.ShowMessageBox(null, "It's over.", "Closed");
}
public void OnClosing(CancelEventArgs e)
{
e.Cancel = true;
}
public async Task OnClosingAsync(CancelEventArgs e)
{
var quit = await _dialogService.ShowMessageBoxAsync(this, "Do you really want to quit? ", "Confirmation", HanumanInstitute.MvvmDialogs.FrameworkDialogs.MessageBoxButton.YesNo);
e.Cancel = quit != true;
}
public void OnLoaded()
{
Text = "Loaded!";
}
}