private void CreateContainers() { var generator = Owner.ItemContainerGenerator; if (Owner.Bounds.Size.IsDefault) { if ((Items.Count() > 0) && !_estimated) { PdmLogger.Log(0, PdmLogger.IndentEnum.In, $"Estimate {Id} Items:{Items} "); var materialized = generator.Materialize(0, Items.ElementAt(0)); VirtualizingPanel.Children.Insert(0, materialized.ContainerControl); materialized.ContainerControl.Measure(Size.Infinity); VirtualizingAverages.AddContainerSize(GroupControl.TemplatedParent, Items.ElementAt(0), materialized.ContainerControl); //VirtualizingPanel.Children.RemoveAt(0); //generator.Dematerialize(0, 1); //ItemsPresenter.InvalidateMeasure(); _estimated = true; PdmLogger.Log(1, PdmLogger.IndentEnum.Out, $"Estimated {Id} Items:{Items} "); } } else if (Items != null && VirtualizingPanel.IsAttachedToVisualTree) { _realizedChildren.AddChildren(); } _estimatedSize = VirtualizingAverages.GetEstimatedExtent(GroupControl.TemplatedParent, Items, Vertical); }
public ItemVirtualizerSmooth(ItemsPresenter owner) : base(owner) { Id = _idCount++; _realizedChildren = new RealizedItems(Owner, GroupControl, Id); PdmLogger.Log(30, PdmLogger.IndentEnum.Nothing, $"Constructing {Id}, {Items} {++_gcount}"); }
/// <summary> /// Initializes a new instance of the <see cref="GroupContainerGenerator"/> class. /// </summary> /// <param name="owner">The immediate owner of the control.</param> public GroupContainerGenerator(ItemsControl owner) : base(owner) { Contract.Requires <ArgumentNullException>(owner != null); // _groupControl = new GroupController() { TemplatedParent = owner }; PdmLogger.Log(30, PdmLogger.IndentEnum.Nothing, $"Construct GroupContainerGenerator {Id} {_str} {++_gcount00}"); }
/// <inheritdoc/> protected override IControl CreateContainer(object item) { var container = item as GroupItem; if (container != null) { return(container); } else { var itemsControl = Owner as ItemsControl; var presenter = itemsControl.Presenter as ItemsPresenter; var result = new GroupItem(itemsControl, (GroupingViewInternal)item); PdmLogger.Log(4, PdmLogger.IndentEnum.Nothing, $"Create GroupItem {result.Id} from {Id} with {item}"); result.SetValue(GroupItem.TemplatedParentProperty, Owner, BindingPriority.TemplatedParent); // result.GroupControl = _groupControl; result.SetValue(GroupItem.ItemsPanelProperty, itemsControl.ItemsPanel); result.ItemTemplate = itemsControl?.ItemTemplate; if (presenter != null) { result.VirtualizationMode = presenter.VirtualizationMode; result.VirtualizingCache = presenter.VirtualizingCache; } if (!(item is IControl)) { result.DataContext = item; } return(result); } }
public void RemoveChildren() { var toRemove = new List <ItemContainerInfo>(); foreach (var item in _generator.Containers) { if (_info.CheckForRemoval(item.Index)) { toRemove.Add(item); } } if (toRemove.Count != 0) { PdmLogger.Log(30, PdmLogger.IndentEnum.Nothing, $"RemoveChildren {this} Info {_info} {toRemove.Count}"); } foreach (var toRem in toRemove) { foreach (var container in _generator.Dematerialize(toRem.Index, 1)) { PdmLogger.Log(30, PdmLogger.IndentEnum.Nothing, $"Remove Child {container.ContainerControl}"); _panel.Children.Remove(container.ContainerControl); _groupControl.RemoveItem(container.ContainerControl); } // _groupControl.RemoveGroup(toRem.Item); } }
internal double AddOneChild(RealizedItemsInfo info) { var child = _generator.ContainerFromIndex(_info.Next); if (child == null) { var materialized = _generator.Materialize(_info.Next, _items.ElementAt(_info.Next)); child = materialized.ContainerControl; _panel.Children.Add(child); child.Measure(Size.Infinity); PdmLogger.Log(2, PdmLogger.IndentEnum.Nothing, $"Add new Item {child.DataContext} to {this} {_info._currentOffset:0.00}"); if (VirtualizingAverages.AddContainerSize(_groupControl.TemplatedParent, _items.ElementAt(_info.Next), child)) { _owner.InvalidateMeasure(); } } else { if (child is GroupItem gi) { gi.Presenter?.InvalidateMeasure(); } if (_id == 402) { } child.Measure(Size.Infinity); PdmLogger.Log(2, PdmLogger.IndentEnum.Nothing, $"Add old Item {child.DataContext} to {this} {_info._currentOffset:0.00}"); if (VirtualizingAverages.AddContainerSize(_groupControl.TemplatedParent, _items.ElementAt(_info.Next), child)) { _owner.InvalidateMeasure(); } } return(_info.Vert ? child.DesiredSize.Height : child.DesiredSize.Width); }
private int GetNumInView(double scrollPos) { var last = (int)scrollPos; RemoveOld(); if (RealizedIndex.TryGetValue((int)scrollPos, out var first)) { var firstLocation = first.RelativeOffset; foreach (var item in RealizedIndex) { var offset = item.Value.RelativeOffset - firstLocation; var res = item.Value.Container.ContainerControl.TranslatePoint(new Point(0, 0), _panel); if ((offset <= _scrollContentPresenter.DesiredSize.Height) && (last < item.Key))// Panel.DesiredSize.Height) { if (offset + item.Value.Container.ContainerControl.DesiredSize.Height <= _scrollContentPresenter.DesiredSize.Height) { last = item.Key; } else { last = item.Key - 1; } } } } PdmLogger.Log(3, PdmLogger.IndentEnum.Nothing, $"LastInView02 {scrollPos} {last}"); return(last + 1 - (int)scrollPos); }
public ItemVirtualizerLogical(ItemsPresenter owner) : base(owner) { Id = _idCount++; _realizedChildren = new RealizedItems(Owner, GroupControl, Id); _scrollContentPresenter = Owner.FindAncestorOfType <ScrollContentPresenter>(); PdmLogger.Log(30, PdmLogger.IndentEnum.Nothing, $"Constructing {Id}, {Items} {++_gcount}"); }
public GroupItem(ItemsControl itemsControl, IGroupingView items) { if (itemsControl is GroupItem gi) { Level = gi.Level + 1; } Name = $"Level{Level,2:00}"; Id = _idCount++; Items = items; PdmLogger.Log(30, PdmLogger.IndentEnum.Nothing, $"Construct GroupItem {Id} {Items} {++_gcount}"); }
/// <summary> /// Initializes a new instance of the <see cref="ItemContainerGenerator"/> class. /// </summary> /// <param name="owner">The owner control.</param> public ItemContainerGenerator(IControl owner) { Contract.Requires <ArgumentNullException>(owner != null); Owner = owner; Id = _count++; if (Owner is ItemsControl ic) { _str = $"{ic.Items}"; } PdmLogger.Log(30, PdmLogger.IndentEnum.Nothing, $"Construct ItemContainerGenerator {Id} {_str} {++_gcount}"); }
/// <inheritdoc/> public override Size MeasureOverride(Size availableSize) { PdmLogger.Log(0, PdmLogger.IndentEnum.In, $"Measure Realized {_realizedChildren} {availableSize} {++_measureCount} {!Owner.Bounds.Size.IsDefault}"); UpdateControls(); if (!_scrollViewer.Bounds.Size.IsDefault) { _realizedChildren.RemoveChildren(); } PdmLogger.Log(1, PdmLogger.IndentEnum.Out, $"Measured Realized {_realizedChildren} {_estimatedSize} {_measureCount} {!Owner.Bounds.Size.IsDefault}"); if (VirtualizingPanel.ScrollDirection == Layout.Orientation.Vertical) { return(_estimatedSize); } return(_estimatedSize); }
public void AddChildren() { // _groupControl.RemoveGroup(_items); var numItems = _items.Count(); _info.SetPanelRelative(-_panel.TranslatePoint(new Point(0, 0), _scrollViewer).Value, _scrollViewer.Bounds.Size); _info.SetFirst(_scrollViewer.Offset); PdmLogger.Log(3, PdmLogger.IndentEnum.Nothing, $"BeforeAdd {this} {_info}"); while (_info.RealizeNeeded(numItems)) { _info.AddOffset(AddOneChild(_info)); PdmLogger.Log(3, PdmLogger.IndentEnum.Nothing, $"Add Item {this} {_info}"); } PdmLogger.Log(2, PdmLogger.IndentEnum.Nothing, $"AddChildren Realized {this} Info {_info} Scroller Height {_scrollViewer.Bounds.Height:0.00}"); // _groupControl.AddGroup(_info, _items, _generator); }
public void RemoveItem(IControl control) { PdmLogger.Log(3, PdmLogger.IndentEnum.Nothing, $"Rem Item"); var toRemove = new List <int>(); foreach (var item in RealizedIndex) { if (item.Value.Container.ContainerControl == control) { toRemove.Add(item.Key); } } foreach (var item in toRemove) { PdmLogger.Log(3, PdmLogger.IndentEnum.Nothing, $"Rem Item00 {RealizedIndex[item].Container.ContainerControl.DataContext}"); RealizedIndex.Remove(item); } }
private void RemoveOld() { // PdmLogger.Log(3, PdmLogger.IndentEnum.Nothing, $"Rem Group"); var toRemove = new List <int>(); foreach (var item in RealizedIndex) { if ((item.Value.Container == null) || (item.Value.Container.ContainerControl.Parent == null)) { toRemove.Add(item.Key); } } foreach (var item in toRemove) { PdmLogger.Log(3, PdmLogger.IndentEnum.Nothing, $"Rem Item02 {RealizedIndex[item].Container.ContainerControl.DataContext}"); RealizedIndex.Remove(item); } }
internal void RemoveItems(IItemContainerGenerator itemContainerGenerator) { var toRemove = new List <int>(); foreach (var container in itemContainerGenerator.Containers) { foreach (var item in RealizedIndex) { if (item.Value.Container == container) { toRemove.Add(item.Key); } } } foreach (var item in toRemove) { PdmLogger.Log(3, PdmLogger.IndentEnum.Nothing, $"Rem Item01 {RealizedIndex[item].Container.ContainerControl.DataContext}"); RealizedIndex.Remove(item); } }
public ListBoxItem() { Id = _idCount++; PdmLogger.Log(30, PdmLogger.IndentEnum.Nothing, $"Constructing ListBoxItem, {Id} {++_gcount}"); }