protected void ApplyTemplate() { ReleaseVisualTree(); ControlTemplate template = Template ?? DefaultControlTemplate; _visualTree = template(this); // TODO: OnApplyTemplate }
public static Region GetRegion(UiElement descendant) { while (descendant != null && !(descendant is Region)) { descendant = descendant.Parent; } return (Region)descendant; }
public Generation(object item, UiElement container) { Container = container; Item = item; }
public void ReleaseContainer(UiElement container) { for (int i = _generations.Count - 1; i >= 0; i--) { if (((Generation)_generations[i]).Container == container) { _generations.RemoveAt(i); break; } } }
public object GetItemForContainer(UiElement container) { for (int i = _generations.Count - 1; i >= 0; i--) { Generation g = (Generation)_generations[i]; if (g.Container == container) { return g.Item; } } return null; }
public int GetIndexForContainer(UiElement container) { object item = GetItemForContainer(container); if (item == null) return -1; return ((ArrayListExt) (object) _allItems()).BinarySearch(item, _comparer); }
public int GetIndexForContainer(UiElement container) { object item = GetItemForContainer(container); if (item == null) return -1; return _allItems.IndexOf(item); }
protected void ReleaseVisualTree() { // TODO _visualTree = null; }
private void Synchronize(bool clear) { int available = GetAvailableItemCount(); bool changed = false; if (_scroller != null) { if (clear || (available == 0)) { if (_itemContainerGenerator != null) { _desiredFirstItem = _itemContainerGenerator.GetIndexForContainer(_firstItemContainer); if (_desiredFirstItem < 0) { _desiredFirstItem = _firstItem; } } for (int i = Math.Max(_firstRealizedItem, 0); i <= _lastRealizedItem; i++) { ReleaseContainer(i); changed = true; } _firstItem = -1; _firstItemContainer = null; _lastItem = -1; _firstRealizedItem = -1; _lastRealizedItem = -1; } if (available > 0) { _content.Height(available*_fixedItemHeight); _desiredFirstItem = Math.Max(0, Math.Min(_desiredFirstItem, GetAvailableItemCount())); if (_desiredFirstItem != _firstItem) { changed = true; } int firstRequired = _desiredFirstItem; int viewSize = _scroller.GetInnerHeight(); double buffer = viewSize / (double)_fixedItemHeight; int usableBuffer = Math.Floor(buffer); int lastRequired = firstRequired + usableBuffer - 1; if (lastRequired > available - 1) { int overshot = lastRequired - available + 1; firstRequired = Math.Max(firstRequired - overshot, 0); lastRequired = available - 1; } int firstAllowed = firstRequired - 2; int lastAllowed = lastRequired + 2; _firstItem = firstRequired; _desiredFirstItem = _firstItem; _firstItemContainer = _itemContainerGenerator.GetContainerForIndex(_firstItem); _lastItem = lastRequired; if (buffer - usableBuffer > 0) { lastRequired = Math.Min(lastRequired + 1, available - 1); } ShowScrollbar((_firstItem > 0) || (_viewportLines < available)); int layoutWidth = _content.GetInnerWidth(); // add any missing elements for (int i = firstRequired; i <= lastRequired; i++) { if (_realizedItems[i] == null) { changed = true; UiElement item = _itemContainerGenerator.GenerateContainer(i); _realizedItems[i] = item; item.Parent = this; item.Measure(new Size(layoutWidth, _fixedItemHeight)); AxisArrangement v = ArrangeAxis(item.YAxis, item.MeasuredSize.Height, _fixedItemHeight); v.Position += i * _fixedItemHeight; item.Arrange(ArrangeAxis(item.XAxis, item.MeasuredSize.Width, _content.GetInnerWidth()), v, _content[0]); } } // show the new items _content.CSS("top", (-firstRequired * _fixedItemHeight) + "px"); // remove any unnecessary elements) for (int i = Math.Max(_firstRealizedItem, 0); i < firstAllowed; i++) { ReleaseContainer(i); } for (int i = lastAllowed + 1; i <= _lastRealizedItem; i++) { ReleaseContainer(i); } _firstRealizedItem = Math.Min(firstRequired, Math.Max(firstAllowed, _firstRealizedItem)); _lastRealizedItem = Math.Max(lastRequired, Math.Min(lastAllowed, _lastRealizedItem)); } else { ShowScrollbar(false); } } if (changed && Changed != null) { Changed(); } }