This repository was archived by the owner on Feb 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckedItem.cs
80 lines (69 loc) · 1.98 KB
/
CheckedItem.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
using System;
using System.ComponentModel;
using System.Windows.Input;
namespace Jam.Shell
{
public class CheckedItem<T> : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private bool m_IsChecked;
private T m_Item;
private ICommand m_Command; //Command that can be attached to a menuitem.
private Action<T, bool> m_CheckStateChanged; //function that is executed when the checkstate of an item changes.
public CheckedItem(T item, ICommand pCommand, bool isChecked = false)
{
this.m_Item = item;
this.m_IsChecked = isChecked;
this.m_Command = pCommand;
}
public CheckedItem(T pItem, Action<T, bool> pCheckStateChanged, bool pIsChecked = false)
{
m_Item = pItem;
m_CheckStateChanged = pCheckStateChanged;
m_IsChecked = pIsChecked;
}
public T Item
{
get
{
return m_Item;
}
set
{
m_Item = value;
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Item"));
}
}
public bool IsChecked
{
get
{
return m_IsChecked;
}
set
{
m_IsChecked = value;
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("IsChecked"));
if (m_CheckStateChanged != null)
{
m_CheckStateChanged(Item, m_IsChecked);
}
}
}
public ICommand Command
{
get
{
return m_Command;
}
set
{
m_Command = value;
}
}
public override string ToString()
{
return m_Item.ToString();
}
}
}