/// <summary>When overridden in a derived class, positions child elements and determines a size for a <see cref="T:System.Windows.FrameworkElement"/> derived class.</summary> /// <param name="finalSize">The final area within the parent that this element should use to arrange itself and its children.</param> /// <returns>The actual size used.</returns> protected override Size ArrangeOverride(Size finalSize) { var surfaceSize = AdornedElement.RenderSize; if (_horizontal.Visibility == Visibility.Visible) { var scrollTop = surfaceSize.Height - SystemParameters.HorizontalScrollBarHeight; var scrollWidth = _vertical.Visibility == Visibility.Visible ? surfaceSize.Width - SystemParameters.VerticalScrollBarWidth : surfaceSize.Width; if (scrollTop < 0d) { scrollTop = 0d; } var scrollHeight = SystemParameters.HorizontalScrollBarHeight; if (scrollHeight > finalSize.Height) { scrollHeight = finalSize.Height; } _horizontal.Arrange(GeometryHelper.NewRect(0, scrollTop, scrollWidth, scrollHeight, true)); } if (_vertical.Visibility == Visibility.Visible) { var scrollLeft = Math.Max(surfaceSize.Width - SystemParameters.VerticalScrollBarWidth, 0d); var scrollWidth = SystemParameters.VerticalScrollBarWidth; if (scrollWidth > finalSize.Width) { scrollWidth = finalSize.Width; } var scrollHeight = _horizontal.Visibility == Visibility.Visible ? surfaceSize.Height - SystemParameters.HorizontalScrollBarHeight : surfaceSize.Height; _vertical.Arrange(GeometryHelper.NewRect(scrollLeft, 0, scrollWidth, scrollHeight, true)); } return(finalSize); }
/// <summary> /// After measurement arrange the scrollbars of the panel. /// </summary> protected override Size ArrangeOverride(Size bounds) { var scrollHeight = HtmlHeight(bounds) + Padding.Top + Padding.Bottom; scrollHeight = scrollHeight > 1 ? scrollHeight : 1; var scrollWidth = HtmlWidth(bounds) + Padding.Left + Padding.Right; scrollWidth = scrollWidth > 1 ? scrollWidth : 1; _verticalScrollBar.Arrange(new Rect(System.Math.Max(bounds.Width - _verticalScrollBar.Width - BorderThickness.Right, 0), BorderThickness.Top, _verticalScrollBar.Width, scrollHeight)); _horizontalScrollBar.Arrange(new Rect(BorderThickness.Left, System.Math.Max(bounds.Height - _horizontalScrollBar.Height - BorderThickness.Bottom, 0), scrollWidth, _horizontalScrollBar.Height)); if (_htmlContainer != null) { if (_verticalScrollBar.Visibility == Visibility.Visible) { _verticalScrollBar.ViewportSize = HtmlHeight(bounds); _verticalScrollBar.SmallChange = 25; _verticalScrollBar.LargeChange = _verticalScrollBar.ViewportSize * .9; _verticalScrollBar.Maximum = _htmlContainer.ActualSize.Height - _verticalScrollBar.ViewportSize; } if (_horizontalScrollBar.Visibility == Visibility.Visible) { _horizontalScrollBar.ViewportSize = HtmlWidth(bounds); _horizontalScrollBar.SmallChange = 25; _horizontalScrollBar.LargeChange = _horizontalScrollBar.ViewportSize * .9; _horizontalScrollBar.Maximum = _htmlContainer.ActualSize.Width - _horizontalScrollBar.ViewportSize; } // update the scroll offset because the scroll values may have changed UpdateScrollOffsets(); } return(bounds); }
/// <summary>When overridden in a derived class, positions child elements and determines a size for a <see cref="T:System.Windows.FrameworkElement"/> derived class.</summary> /// <param name="finalSize">The final area within the parent that this element should use to arrange itself and its children.</param> /// <returns>The actual size used.</returns> protected override Size ArrangeOverride(Size finalSize) { // TODO: Need to check why RenderSize was often different from finalSize, and why we used RenderSize in the first place. var surfaceSizeWidth = Math.Min(AdornedElement.RenderSize.Width, finalSize.Width); var surfaceSizeHeight = Math.Min(AdornedElement.RenderSize.Height, finalSize.Height); if (_horizontal.Visibility == Visibility.Visible) { var scrollTop = surfaceSizeHeight - SystemParameters.HorizontalScrollBarHeight; var scrollWidth = _vertical.Visibility == Visibility.Visible ? surfaceSizeWidth - SystemParameters.VerticalScrollBarWidth : surfaceSizeWidth; if (scrollTop < 0d) { scrollTop = 0d; } var scrollHeight = SystemParameters.HorizontalScrollBarHeight; if (scrollHeight > finalSize.Height) { scrollHeight = finalSize.Height; } _horizontal.Arrange(GeometryHelper.NewRect(0, scrollTop, scrollWidth, scrollHeight, true)); } if (_vertical.Visibility == Visibility.Visible) { var scrollLeft = Math.Max(surfaceSizeWidth - SystemParameters.VerticalScrollBarWidth, 0d); var scrollWidth = SystemParameters.VerticalScrollBarWidth; if (scrollWidth > finalSize.Width) { scrollWidth = finalSize.Width; } var scrollHeight = _horizontal.Visibility == Visibility.Visible ? surfaceSizeHeight - SystemParameters.HorizontalScrollBarHeight : surfaceSizeHeight; _vertical.Arrange(GeometryHelper.NewRect(scrollLeft, 0, scrollWidth, scrollHeight, true)); } return(finalSize); }
/// <summary>When overridden in a derived class, positions child elements and determines a size for a <see cref="T:System.Windows.FrameworkElement"/> derived class.</summary> /// <param name="finalSize">The final area within the parent that this element should use to arrange itself and its children.</param> /// <returns>The actual size used.</returns> protected override Size ArrangeOverride(Size finalSize) { var surfaceSize = AdornedElement.RenderSize; if (_vertical.Visibility == Visibility.Visible) { _vertical.Arrange(GeometryHelper.NewRect(surfaceSize.Width - SystemParameters.VerticalScrollBarWidth, 0, SystemParameters.VerticalScrollBarWidth, surfaceSize.Height)); } return(finalSize); }
protected override Size ArrangeOverride(Size finalSize) { sb_v.Arrange(new Rect(finalSize.Width - sb_v.DesiredSize.Width, 0, sb_v.DesiredSize.Width, finalSize.Height - sb_h.DesiredSize.Width)); sb_h.Arrange(new Rect(0, finalSize.Height - sb_h.DesiredSize.Height, finalSize.Width - sb_v.DesiredSize.Width, sb_h.DesiredSize.Height)); double height = 0.0; for (int i = 0; i < vcount; i++) { vits[i].Arrange(new Rect(-vwrect.X, height, vits[i].Width, vits[i].Height)); height += vits[i].Height; } for (int i = vcount; i < vits.Count(); i++) { vits[i].Arrange(new Rect(0, 0, 0, 0)); } return(finalSize); }
protected override Size ArrangeOverride(Size finalSize) { int firstRow = Cells.GetInitialRow(); foreach (var cell in Cells.GetVisibleCells()) { double width = AccumulatedColumnWidths[cell.Column.Index + 1] - AccumulatedColumnWidths[cell.Column.Index] - GridControl.VerticalLinesThickness; cell.Arrange(new Rect(AccumulatedColumnWidths[cell.Column.Index], AccumulatedRowHeights[cell.Row - firstRow], width, cell.DesiredSize.Height)); } UpdateGridLines(); ScrollBar.Arrange(new Rect(finalSize.Width - ScrollBar.Width, 0.0, ScrollBar.Width, finalSize.Height)); return(finalSize); void UpdateGridLines() { int lastAccumulatedColumnWidthsIndex = AccumulatedColumnWidths.Count - 1; while (ColumnLines.Count > lastAccumulatedColumnWidthsIndex) { var columnLine = ColumnLines[ColumnLines.Count - 1]; ColumnLines.Remove(columnLine); LogicalChildren.Remove(columnLine); VisualChildren.Remove(columnLine); } while (lastAccumulatedColumnWidthsIndex > ColumnLines.Count) { Line columnLine = new Line(); columnLine.Stroke = GridControl.VerticalLinesBrush; columnLine.StrokeThickness = GridControl.VerticalLinesThickness; ColumnLines.Add(columnLine); LogicalChildren.Add(columnLine); VisualChildren.Add(columnLine); } int lastAccumulatedRowHeightsIndex = AccumulatedRowHeights.Count(rh => !Double.IsNaN(rh)) - 1; while (RowLines.Count > lastAccumulatedRowHeightsIndex) { var rowLine = RowLines[RowLines.Count - 1]; RowLines.Remove(rowLine); LogicalChildren.Remove(rowLine); VisualChildren.Remove(rowLine); } while (lastAccumulatedRowHeightsIndex > RowLines.Count) { Line rowLine = new Line(); rowLine.Stroke = GridControl.HorizontalLinesBrush; rowLine.StrokeThickness = GridControl.HorizontalLinesThickness; RowLines.Add(rowLine); LogicalChildren.Add(rowLine); VisualChildren.Add(rowLine); } for (int i = 0; i < RowLines.Count; i++) { double y = AccumulatedRowHeights[i + 1] - GridControl.HorizontalLinesThickness / 2.0; RowLines[i].StartPoint = new Point(0.0, y); RowLines[i].EndPoint = new Point(AccumulatedColumnWidths[lastAccumulatedColumnWidthsIndex], y); } for (int i = 0; i < ColumnLines.Count; i++) { double x = AccumulatedColumnWidths[i + 1] - GridControl.VerticalLinesThickness / 2.0; ColumnLines[i].StartPoint = new Point(x, 0.0); ColumnLines[i].EndPoint = new Point(x, AccumulatedRowHeights[lastAccumulatedRowHeightsIndex]); } foreach (var line in RowLines.Concat(ColumnLines)) { line.InvalidateMeasure(); line.Measure(Size.Infinity); } } }
protected override void OnArrange(Vector2F position, Vector2F size) { // This method handles only the content and the scroll bars. Other visual children are // ignored. Vector4 padding = Padding; var horizontalScrollBarVisibility = HorizontalScrollBarVisibility; var verticalScrollBarVisibility = VerticalScrollBarVisibility; // Determine visibility of scroll bars and size of viewport. // Pass 1: Assume that scroll bars are invisible and that the viewport takes // up all available space. Vector2F viewportSize = new Vector2F(size.X - padding.X - padding.Z, size.Y - padding.Y - padding.W); bool horizontalScrollBarVisible, verticalScrollBarVisible; CalculateViewport(size, padding, horizontalScrollBarVisibility, verticalScrollBarVisibility, out horizontalScrollBarVisible, out verticalScrollBarVisible, ref viewportSize); // Pass 2: It is possible that a scroll bar was made visible in Pass 1 and has // reduced the viewport size so that the other scrollbar is needed too. CalculateViewport(size, padding, horizontalScrollBarVisibility, verticalScrollBarVisibility, out horizontalScrollBarVisible, out verticalScrollBarVisible, ref viewportSize); // Now, we know if the bars are visible and the exact viewport size. Vector2F contentPosition = new Vector2F( position.X + padding.X, position.Y + padding.Y); float verticalOverlap = 0; float horizontalOverlap = 0; if (_isTouchDevice) { // On phone the bars overlap the content area. // --> Make sure that the scroll bars do not overlap each other. if (horizontalScrollBarVisible) verticalOverlap = _horizontalScrollBar.DesiredHeight; if (verticalScrollBarVisible) horizontalOverlap = _verticalScrollBar.DesiredWidth; } // Set bar properties. Remeasure with the new properties and arrange the bars. if (horizontalScrollBarVisible) { _horizontalScrollBar.Minimum = 0; _horizontalScrollBar.Maximum = Math.Max(0, ExtentWidth - viewportSize.X); _horizontalScrollBar.ViewportSize = Math.Min(1, viewportSize.X / ExtentWidth); _horizontalScrollBar.Arrange( new Vector2F(contentPosition.X, position.Y + size.Y - padding.W - _horizontalScrollBar.DesiredHeight), new Vector2F(viewportSize.X - horizontalOverlap, _horizontalScrollBar.DesiredHeight)); } if (verticalScrollBarVisible) { _verticalScrollBar.Minimum = 0; _verticalScrollBar.Maximum = Math.Max(0, ExtentHeight - viewportSize.Y); _verticalScrollBar.ViewportSize = Math.Min(1, viewportSize.Y / ExtentHeight); _verticalScrollBar.Arrange( new Vector2F(position.X + size.X - padding.Z - _verticalScrollBar.DesiredWidth, contentPosition.Y), new Vector2F(_verticalScrollBar.DesiredWidth, viewportSize.Y - verticalOverlap)); } // Store content bounds for clipping. _contentBounds = new RectangleF(contentPosition.X, contentPosition.Y, viewportSize.X, viewportSize.Y); ViewportWidth = viewportSize.X; ViewportHeight = viewportSize.Y; var content = Content; if (content == null) return; // Get content position and content size. Consider disabled bars and the scrolling offsets. Vector2F contentSize = new Vector2F(content.DesiredWidth, content.DesiredHeight); if (horizontalScrollBarVisibility == ScrollBarVisibility.Disabled) contentSize.X = viewportSize.X; else contentPosition.X -= HorizontalOffset; if (verticalScrollBarVisibility == ScrollBarVisibility.Disabled) contentSize.Y = viewportSize.Y; else contentPosition.Y -= VerticalOffset; if (content.HorizontalAlignment == HorizontalAlignment.Stretch) contentSize.X = Math.Max(contentSize.X, viewportSize.X); if (content.VerticalAlignment == VerticalAlignment.Stretch) contentSize.Y = Math.Max(contentSize.Y, viewportSize.Y); content.Arrange(contentPosition, contentSize); }