public override void Add(UiView view) { if (!_children.Contains(view)) { _children.Add(view); view.Parent = this; view.RegisterView(); if (_added) { view.ViewAdded(); } OnChildrenModified(); ShouldRecalcLayout(); } }
public virtual void Insert(int index, UiView view) { if (!_children.Contains(view)) { _children.Insert(index, view); view.Bounds = CalculateChildBounds(view); view.Parent = this; view.RegisterView(); if (_added) { view.ViewAdded(); } OnChildrenModified(); } }
void Recalculate() { _newItems.Clear(); lock (_items) { int count = _items.Count; int added = 0; int numberOfElements = 0; int maxAdd = count == 0 ? _maxAddFirstTime : _maxAddOneTime; for (int idx = 0; idx < count; ++idx) { object bind = _items.ElementAt(_reverse ? count - idx - 1 : idx); UiView view; _bindingToElement.TryGetValue(bind, out view); if (view == null) { if (added < maxAdd) { DefinitionFile template; if (_additionalTemplates == null || !_additionalTemplates.TryGetValue(bind.GetType(), out template)) { template = _template; } view = (UiView)template.CreateInstance(Controller, bind); _newItems.Add(view); added++; } else { continue; } } if (numberOfElements < _itemViews.Count) { _itemViews[numberOfElements] = view; } else { _itemViews.Add(view); } numberOfElements++; } if (_itemViews.Count > numberOfElements) { _itemViews.RemoveRange(numberOfElements, _itemViews.Count - numberOfElements); } } for (int idx = 0; idx < _newItems.Count; ++idx) { UiView view = _newItems[idx]; lock (_childrenLock) { _bindingToElement.Add(view.Binding, view); _children.Add(view); } view.Parent = this; view.RegisterView(); view.ViewAdded(); view.ViewUpdate(0); } RecalculatePositionsAndScroll(); }