84 lines
2.0 KiB
C#
84 lines
2.0 KiB
C#
namespace InspectionUI.ViewModels
|
|
{
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
public class ItemsGridRowVM : VM, IEnumerable<ItemsGridCellVM>
|
|
{
|
|
private readonly IList<ItemsGridCellVM> cells;
|
|
|
|
public ItemsGridRowVM() : base()
|
|
{
|
|
this.cells = new List<ItemsGridCellVM>();
|
|
}
|
|
|
|
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<ItemsGridCellVM> GetEnumerator()
|
|
{
|
|
return this.cells.GetEnumerator();
|
|
}
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
{
|
|
return this.GetEnumerator();
|
|
}
|
|
|
|
protected void Set<T>(Action propertySetterAction, T newValue, string format, int index)
|
|
{
|
|
this.Set(propertySetterAction);
|
|
this.Set(newValue, format, index);
|
|
}
|
|
|
|
protected void Set<T>(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<ItemsGridCellVM> setter, int index)
|
|
{
|
|
this.DispatcherInvoke(() => setter(this[index]));
|
|
}
|
|
}
|
|
} |