-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractVectorCollection.cs
More file actions
63 lines (55 loc) · 2 KB
/
AbstractVectorCollection.cs
File metadata and controls
63 lines (55 loc) · 2 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
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using Interfaces;
namespace EngineersTools
{
public abstract class AbstractVectorCollection : ObservableCollection<IVector>
{
private string _DefaultPrefix = " ";
public string DefaultPrefix
{
get { return _DefaultPrefix; }
set { _DefaultPrefix = value; }
}
private void _InitialiseEvents()
{
CollectionChanged += _CollectionChanged;
}
public AbstractVectorCollection() : base()
{
_InitialiseEvents();
}
public AbstractVectorCollection(IEnumerable<IVector> collection) : base(collection)
{
_InitialiseEvents();
}
private void _CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
IVector item = (IVector)e.NewItems[0];
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
item.Position = Count;
if (string.IsNullOrEmpty(item.Header)) item.Header = DefaultPrefix + Count;
ItemsAdded?.Invoke(this, e);
break;
case NotifyCollectionChangedAction.Remove:
ItemsRemoved?.Invoke(this, e);
break;
case NotifyCollectionChangedAction.Replace:
break;
case NotifyCollectionChangedAction.Move:
break;
case NotifyCollectionChangedAction.Reset:
break;
default:
break;
}
}
public delegate void ItemsAddedHandler(object sender, NotifyCollectionChangedEventArgs e);
public event ItemsAddedHandler ItemsAdded;
public delegate void ItemsRemovedHandler(object sender, NotifyCollectionChangedEventArgs e);
public event ItemsRemovedHandler ItemsRemoved;
}
}