-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMessageBoxViewModel.cs
More file actions
74 lines (57 loc) · 1.68 KB
/
MessageBoxViewModel.cs
File metadata and controls
74 lines (57 loc) · 1.68 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
using System;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Dialogs;
namespace SampleApp.ViewModels;
public class MessageBoxViewModel : BindableBase, IDialogAware
{
private int _maxHeight;
private int _maxWidth;
private string _message = "This feature is not implemented";
private string _title = "Notice";
public MessageBoxViewModel()
{
Title = "Notice";
MaxHeight = 800;
MaxWidth = 600;
}
public DialogCloseListener RequestClose { get; }
public DelegateCommand<string> CmdResult => new((string buttonResult) =>
{
// Dialog's ButtonResult types:
// None = 0
// OK = 1
// Cancel = 2
// Abort = 3
// Retry = 4
// Ignore = 5
// Yes = 6
// No = 7
ButtonResult result = ButtonResult.OK;
if (int.TryParse(buttonResult, out int intResult))
result = (ButtonResult)intResult;
RaiseRequestClose(new DialogResult(result));
});
public int MaxHeight { get => _maxHeight; set => SetProperty(ref _maxHeight, value); }
public int MaxWidth { get => _maxWidth; set => SetProperty(ref _maxWidth, value); }
public string Message { get => _message; set => SetProperty(ref _message, value); }
public string Title { get => _title; set => SetProperty(ref _title, value); }
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
public void OnDialogOpened(IDialogParameters parameters)
{
var title = parameters.GetValue<string>("title");
if (!string.IsNullOrEmpty(title))
Title = title;
Message = parameters.GetValue<string>("message");
}
public virtual void RaiseRequestClose(IDialogResult dialogResult)
{
RequestClose.Invoke(dialogResult);
}
}