-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathSelectableItem.cs
More file actions
88 lines (78 loc) · 1.6 KB
/
SelectableItem.cs
File metadata and controls
88 lines (78 loc) · 1.6 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
using System;
using Windows.UI.Popups;
using System.Threading.Tasks;
namespace Waher.Mock
{
/// <summary>
/// Abstract base class for selectable items.
/// </summary>
public abstract class SelectableItem
{
private bool selected = false;
/// <summary>
/// Abstract base class for selectable items.
/// </summary>
public SelectableItem()
{
}
/// <summary>
/// Raises an event.
/// </summary>
/// <param name="h">Event handler.</param>
protected async Task Raise(EventHandler h)
{
if (!(h is null))
{
try
{
h(this, EventArgs.Empty);
}
catch (Exception ex)
{
MessageDialog Dialog = new MessageDialog(ex.Message, "Error");
await Dialog.ShowAsync();
}
}
}
/// <summary>
/// If the node is selected.
/// </summary>
public bool IsSelected
{
get => this.selected;
set
{
if (this.selected != value)
{
this.selected = value;
if (this.selected)
this.OnSelected();
else
this.OnDeselected();
}
}
}
/// <summary>
/// Event raised when the node has been selected.
/// </summary>
public event EventHandler Selected = null;
/// <summary>
/// Event raised when the node has been deselected.
/// </summary>
public event EventHandler Deselected = null;
/// <summary>
/// Raises the <see cref="Selected"/> event.
/// </summary>
protected virtual Task OnSelected()
{
return this.Raise(this.Selected);
}
/// <summary>
/// Raises the <see cref="Deselected"/> event.
/// </summary>
protected virtual Task OnDeselected()
{
return this.Raise(this.Deselected);
}
}
}