namespace InspectionUI.ViewModels { using System; using System.Collections; using System.Collections.Generic; using System.Linq; public class ItemsGridRowVM : VM, IEnumerable { private readonly IList cells; public ItemsGridRowVM() : base() { this.cells = new List(); } protected ItemsGridCellVM this[int index] { get { if (index >= this.cells.Count) { return default(ItemsGridCellVM); } return this.cells[index]; } } protected int LastIndex { get => this.Count() - 1; } public void Add(ItemsGridCellVM value) { this.cells.Add(value); } public void Clear() { foreach (var cell in this.cells) { cell.Dispose(); } this.cells.Clear(); } public IEnumerator GetEnumerator() { return this.cells.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } protected void Set(Action propertySetterAction, T newValue, string format, int index) { this.Set(propertySetterAction); this.Set(newValue, format, index); } protected void Set(T value, string format, int index) { this.DispatcherInvoke(() => { if (string.IsNullOrWhiteSpace(format)) { format = "{0}"; } this[index].Value = string.Format(format, value); }); } protected void Set(Action setter, int index) { this.DispatcherInvoke(() => setter(this[index])); } } }