It is not related to GUI. I have a class with:
- Private
List, which is edited inside the class. - Open
IReadOnlyCollectionproperty for access to privateList - Public
eventfor notification onListchanging
A list stores objects with properties. The class can changed an item's properties and notify about it. The user can only read an item's properties. I only picked this option.
class MortarInfo
{
public double Angle { get; private set; }
public bool State { get; private set; }
public MortarInfo(double angle, bool state)
{
Angle = angle;
State = state;
}
}
class Mortars
{
private List<MortarInfo> _mortarsInfo;
private ReadOnlyCollection<MortarInfo> _readOnlyMortarsInfo;
public Mortars()
{
_mortarsInfo = new List<MortarInfo>();
_readOnlyMortarsInfo = _mortarsInfo.AsReadOnly();
}
public ReadOnlyCollection<MortarInfo> MortarsInfo
{
get { return _readOnlyMortarsInfo; }
}
public event ListChangedEventHandler MortarsInfoChanged;
public void UpdateAngle(int index, double newAngle)
{
if (_mortarsInfo[index].Angle != newAngle)
{
_mortarsInfo[index] = new MortarInfo(newAngle, _mortarsInfo[index].State);
if (MortarsInfoChanged != null)
{
var arg = new ListChangedEventArgs(ListChangedType.ItemChanged, index);
MortarsInfoChanged(this, arg);
}
}
}
}