protected override Size MeasureOverride(VirtualizingLayoutContext context, Size availableSize) { var state = context.LayoutState as AnimationTagViewLayoutState; var scaler = Scaler; state.LayoutRects.Clear(); int firstColumnIndex = context.ItemCount; int lastColumnIndex = 0; int lastFrameIndex = 0; int xFrameIndex = (int)(context.RealizationRect.Left / scaler) - 1; int yFrameIndex = (int)(context.RealizationRect.Right / scaler) + 1; for (int i = 0; i < context.ItemCount; i++) { var data = (AnimationTag)context.GetItemAt(i); firstColumnIndex = i; if (data.FrameIndex > xFrameIndex) { break; } } for (int i = firstColumnIndex; i < context.ItemCount; i++) { var data = (AnimationTag)context.GetItemAt(i); lastColumnIndex = i + 1;//考虑不被执行的情况 if (data.FrameIndex > yFrameIndex) { break; } } for (int i = firstColumnIndex; i < lastColumnIndex; i++) { var data = (AnimationTag)context.GetItemAt(i); var container = context.GetOrCreateElementAt(i); var rect = new Rect(data.FrameIndex * scaler, 4, 16, 16); state.LayoutRects.Add(rect); container.Measure(new Size(rect.Width, c_railHeight)); } if (context.ItemCount > 0) { lastFrameIndex = ((AnimationTag)context.GetItemAt(context.ItemCount - 1)).FrameIndex; } state.FirstRealizedIndex = firstColumnIndex; return(new Size(lastFrameIndex * scaler + 300, c_railHeight)); }
protected override Size MeasureOverride(VirtualizingLayoutContext context, Size availableSize) { var state = context.LayoutState as TimelineRailState; var scaler = Scaler; state.LayoutRects.Clear(); int firstColumnIndex = context.ItemCount; int lastColumnIndex = 0; int lastFrameIndex = 0; int xFrameIndex = (int)(context.RealizationRect.Left / scaler) - 1; int yFrameIndex = (int)(context.RealizationRect.Right / scaler) + 1; for (int i = 0; i < context.ItemCount; i++) { var data = (TimelineRailItem)context.GetItemAt(i); firstColumnIndex = i; if (data.StartFrameIndex + data.ContinueFramesCount > xFrameIndex) { break; } } for (int i = firstColumnIndex; i < context.ItemCount; i++) { var data = (TimelineRailItem)context.GetItemAt(i); lastColumnIndex = i + 1;//考虑不被执行的情况 if (data.StartFrameIndex > yFrameIndex) { break; } } for (int i = firstColumnIndex; i < lastColumnIndex; i++) { var data = (TimelineRailItem)context.GetItemAt(i); var container = context.GetOrCreateElementAt(i); var rect = new Rect(data.StartFrameIndex * scaler, 0, data.ContinueFramesCount * scaler, c_railHeight); state.LayoutRects.Add(rect); container.Measure(new Size(rect.Width, c_railHeight)); } for (int i = 0; i < context.ItemCount; i++) { var data = (TimelineRailItem)context.GetItemAt(i); lastFrameIndex = Math.Max(lastFrameIndex, data.StartFrameIndex + data.ContinueFramesCount); } state.FirstRealizedIndex = firstColumnIndex; return(new Size(lastFrameIndex * scaler, c_railHeight)); }
private Size ArrangeColumn(VirtualizingLayoutContext context, GroupedLayoutState state, ColumnInfo colInfo, int col, int headerIndex, double startingY, bool widthChanged, out int nextHeaderIndex) { // Note that you MUST call GetOrCreateElement on any items that are in the realized region... that's how // the control tracks which elements it shouldn't dispose. double y = startingY; double x = col * colInfo.ColumnWidth + ColumnSpacing * col; int i = headerIndex; var header = state.GetItemAt(headerIndex); var headerEl = context.GetOrCreateElementAt(headerIndex); headerEl.Arrange(new Rect(x, y, colInfo.ColumnWidth, headerEl.DesiredSize.Height)); y += headerEl.DesiredSize.Height + AfterHeaderSpacing; i++; while (i < context.ItemCount) { if (!(context.GetItemAt(i) is ViewItemTaskOrEvent)) { // End of column break; } var item = state.GetItemAt(i); // Logic technically ignores height of item, but heights are short enough it shouldn't matter if (y < context.RealizationRect.Top || y > context.RealizationRect.Bottom) { y += item.Height.GetValueOrDefault(40); } else { var el = context.GetOrCreateElementAt(i); //if (widthChanged || !item.Arranged) { el.Arrange(new Rect(x, y, colInfo.ColumnWidth, el.DesiredSize.Height)); } y += el.DesiredSize.Height; } // Include item spacing y += ItemSpacing; i++; } // Remove last item spacing (since no item after it) y -= ItemSpacing; nextHeaderIndex = i; return(new Size(colInfo.ColumnWidth, y - startingY)); }
private IList GetItems(VirtualizingLayoutContext context) { var result = new List <object>(); for (int i = 0; i < context.ItemCount; i++) { result.Add(context.GetItemAt(i)); } return(result); }
private Size MeasureColumn(VirtualizingLayoutContext context, GroupedLayoutState state, Size availableSizeForElements, int headerIndex, double startingY, bool widthChanged, out int nextHeaderIndex) { // Note that you MUST call GetOrCreateElement on any items that are in the realized region... that's how // the control tracks which elements it shouldn't dispose. double y = startingY; int i = headerIndex; var header = state.GetItemAt(headerIndex); //if (widthChanged || header.Height == null) { var headerEl = context.GetOrCreateElementAt(headerIndex); headerEl.Measure(availableSizeForElements); header.Height = headerEl.DesiredSize.Height; } y += header.Height.Value + AfterHeaderSpacing; i++; while (i < context.ItemCount) { if (!(context.GetItemAt(i) is ViewItemTaskOrEvent)) { // End of column break; } var item = state.GetItemAt(i); // Logic technically ignores height of item, but heights are short enough it shouldn't matter if (y < context.RealizationRect.Top || y > context.RealizationRect.Bottom) { y += item.Height.GetValueOrDefault(40); } else { // Theoretically since tasks/events are removed and then added back when edited, we know they can never change size... // Therefore we can store their measured size, and only call measure if their width changed or height unknown... // However this didn't work in reality, not sure why. //if (widthChanged || item.Height == null) { var itemEl = context.GetOrCreateElementAt(i); itemEl.Measure(availableSizeForElements); item.Height = itemEl.DesiredSize.Height; } y += item.Height.Value; } // Include item spacing y += ItemSpacing; i++; } // Remove last item spacing (since no item after it) y -= ItemSpacing; nextHeaderIndex = i; return(new Size(availableSizeForElements.Width, y - startingY)); }