NavigateBarButtonCollection.cs
6.5 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
* Project : Outlook 2003 Style Navigation Pane
*
* Author : Muhammed ŞAHİN
* eMail : muhammed.sahin@gmail.com
*
* Description : NavigateBarButton collection
*
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace MT.WindowsUI.NavigationPane
{
/// <summary>
/// NavigateBarButton collection
/// </summary>
public class NavigateBarButtonCollection : CollectionBase
{
#region Delegates
internal delegate void OnButtonEventHandler(NavigateBarButtonEventArgs e);
/// <summary>
/// Occurs when remove button in collection
/// </summary>
internal event OnButtonEventHandler OnButtonAdded;
/// <summary>
/// Occurs when add new button in collection
/// </summary>
internal event OnButtonEventHandler OnButtonRemoved;
#endregion
#region Constructors
private NavigateBar NavigationPane;
public NavigateBarButtonCollection(NavigateBar tNavigateBar)
{
this.NavigationPane = tNavigateBar;
}
#endregion
#region Indexer
public NavigateBarButton this[int index]
{
get { return (NavigateBarButton)this.List[index]; }
set
{
if (value is NavigateBarButton)
{
this.List[index] = value;
}
else
throw new Exception("Value must be NavigateBarButton");
}
}
#endregion
#region Methods
/// <summary>
/// Add a new button in collection
/// </summary>
/// <param name="tButton">NavigateBarButton object</param>
public virtual void Add(NavigateBarButton tButton)
{
// Only once
if (!this.Contains(tButton))
this.List.Add(tButton);
}
/// <summary>
/// Add buttons in collection
/// </summary>
/// <param name="tButtons"></param>
public virtual void AddRange(NavigateBarButton[] tButtons)
{
foreach (NavigateBarButton nvb in tButtons)
this.Add(nvb);
}
/// <summary>
/// Remove exist a button from collection
/// </summary>
/// <param name="tButton">NavigateBarButton object</param>
public virtual void Remove(NavigateBarButton tButton)
{
if (this.Contains(tButton))
this.List.Remove(tButton);
}
/// <summary>
/// Remove exist a button from collection using key value
/// </summary>
/// <param name="tKey"></param>
public virtual void RemoveByKey(string tKey)
{
NavigateBarButton nvb = this.FindByKey(tKey);
if (nvb != null)
this.Remove(nvb);
}
/// <summary>
/// Insert a new button in collection
/// </summary>
/// <param name="tIndex">Index no</param>
/// <param name="tButton">NavigateBarButton object</param>
public virtual void Insert(int tIndex, NavigateBarButton tButton)
{
if (!this.Contains(tButton))
this.List.Insert(tIndex, tButton);
}
protected override void OnInsertComplete(int index, object value)
{
base.OnInsertComplete(index, value);
if (OnButtonAdded != null)
OnButtonAdded(new NavigateBarButtonEventArgs(value as NavigateBarButton));
}
protected override void OnRemoveComplete(int index, object value)
{
base.OnRemoveComplete(index, value);
if (OnButtonRemoved != null)
OnButtonRemoved(new NavigateBarButtonEventArgs(value as NavigateBarButton));
}
/// <summary>
/// Check collection
/// </summary>
/// <param name="tButton">NavigateBarButton object</param>
/// <returns>bool</returns>
public virtual bool Contains(NavigateBarButton tButton)
{
return this.List.Contains(tButton);
}
/// <summary>
/// Get index no in collection
/// </summary>
/// <param name="tButton">NavigateBarButton object</param>
/// <returns>int</returns>
public virtual int IndexOf(NavigateBarButton tButton)
{
return this.List.IndexOf(tButton);
}
#endregion
#region Custom Methods
/// <summary>
/// Get displayed button count in panel
/// </summary>
/// <returns></returns>
public int GetDisplayedItemCount()
{
int count = 0;
foreach (NavigateBarButton nvb in this.List)
if (nvb.IsDisplayed && nvb.Visible)
count++;
return count;
}
/// <summary>
/// Search button using key value
/// </summary>
/// <param name="tKey">NavigateBarButton key value</param>
/// <returns></returns>
public NavigateBarButton FindByKey(string tKey)
{
NavigateBarButton retButton = null;
if (string.IsNullOrEmpty(tKey))
return retButton;
foreach (NavigateBarButton nvb in this.List)
{
if (!string.IsNullOrEmpty(nvb.Key) && nvb.Key.Equals(tKey))
{
retButton = nvb;
break;
}
}
return retButton;
}
/// <summary>
/// Set new position in collection
/// </summary>
/// <param name="tButton">NavigateBarButton object</param>
/// <param name="tNewIndex">New index in collection</param>
public void SetChildIndex(NavigateBarButton tButton, int tNewIndex)
{
if (tButton == null)
return;
int oldIndex = this.List.IndexOf(tButton);
// Eğer yeri daha önceli bir konuma alınmışsa
if (oldIndex > tNewIndex)
{
for (int i = oldIndex; i >= (tNewIndex + 1); i--)
this.List[i] = this.List[i - 1];
}
else if (oldIndex < tNewIndex) // Eğer bulunduğu posizyondan sonraki bir posizyona alınmışsa
{
for (int i = oldIndex + 1; i <= tNewIndex; i++)
this.List[i - 1] = this.List[i];
}
this.List[tNewIndex] = tButton;
}
#endregion
}
}