blob: ae6d54bc6757a5e1cf2fdf5820e06dd32bd354d3 (
plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core.Commands;
using Tango.SharedUI;
namespace Tango.SharedUI
{
/// <summary>
/// Represents a dialog view model base class.
/// </summary>
/// <seealso cref="Tango.SharedUI.ViewModel" />
public abstract class DialogViewVM : ViewModel
{
public event Action Accepted;
public event Action Canceled;
/// <summary>
/// Initializes a new instance of the <see cref="DialogViewVM"/> class.
/// </summary>
public DialogViewVM()
{
CanClose = true;
CloseCommand = new RelayCommand(Cancel, (x) => CanClose);
OKCommand = new RelayCommand(Accept, (x) => CanOK());
}
private bool _canClose;
/// <summary>
/// Gets or sets a value indicating whether this dialog can be closed.
/// </summary>
public bool CanClose
{
get { return _canClose; }
set { _canClose = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
}
private bool _isVisible;
/// <summary>
/// Gets or sets a value indicating whether this instance is visible.
/// </summary>
public bool IsVisible
{
get { return _isVisible; }
set { _isVisible = value; RaisePropertyChangedAuto(); }
}
/// <summary>
/// Determines whether this instance can invoke the OK command.
/// </summary>
protected virtual bool CanOK()
{
return true;
}
/// <summary>
/// Gets a value indicating whether the dialog has been confirmed.
/// </summary>
public bool DialogResult { get; private set; }
/// <summary>
/// Gets or sets the close command.
/// </summary>
public RelayCommand CloseCommand { get; set; }
/// <summary>
/// Gets or sets the OK command.
/// </summary>
public RelayCommand OKCommand { get; set; }
/// <summary>
/// Called when the dialog has been shown.
/// </summary>
public virtual void OnShow()
{
IsVisible = true;
}
/// <summary>
/// Invokes the <see cref="Accepted"/> event.
/// </summary>
protected virtual void Accept()
{
IsVisible = false;
DialogResult = true;
Accepted?.Invoke();
}
/// <summary>
/// Invokes the <see cref="Canceled"/> event.
/// </summary>
protected virtual void Cancel()
{
IsVisible = false;
Canceled?.Invoke();
}
/// <summary>
/// Closes the dialog with the specified result.
/// </summary>
/// <param name="result">if set to <c>true</c> accepted.</param>
public void Close(bool result)
{
DialogResult = result;
if (result)
{
Accept();
}
else
{
Cancel();
}
}
}
}
|