private void ArrangeLabel(ContentPresenter label, double value, double offset) { double halfLabelHeight = label.DesiredSize.Height / 2; double halfLabelWidth = label.DesiredSize.Width / 2; bool flipLayout = this.OwnerGauge.MaxValue < this.OwnerGauge.MinValue; double minMaxDiff = Math.Abs(this.OwnerGauge.MaxValue - this.OwnerGauge.MinValue); double valueDiff = flipLayout ? value - this.OwnerGauge.MaxValue : value - this.OwnerGauge.MinValue; double tmp = this.isHorizontal ? halfLabelWidth : halfLabelHeight; double half = flipLayout ? -tmp : tmp; double distanceFromLayoutRectEdge = RadGauge.MapLogicalToPhysicalValue(valueDiff, this.availableExtent, minMaxDiff) - half; if (flipLayout) { distanceFromLayoutRectEdge = this.availableExtent - distanceFromLayoutRectEdge; } double left = 0; double top = 0; if (this.isHorizontal) { left = distanceFromLayoutRectEdge; top = (this.halfAvailableHeight - halfLabelHeight) + offset; } else { left = (this.halfAvailableWidth - halfLabelWidth) + offset; top = this.availableExtent - distanceFromLayoutRectEdge - label.DesiredSize.Height; } label.Arrange(new Rect(new Point(left, top), label.DesiredSize)); }
protected override Size ArrangeOverride(Size arrangeBounds) { InitializeChildrens(); double x = indent; double w = arrangeBounds.Width; double h = arrangeBounds.Height; var size = expander.DesiredSize; expander.Arrange(new Rect(x, (h - size.Height) / 2, size.Width, size.Height)); x += size.Width; if (!icon.ImageReference.IsDefault) { size = icon.DesiredSize; icon.Arrange(new Rect(x, (h - size.Height) / 2, size.Width, size.Height)); x += size.Width; } size = content.DesiredSize; content.Arrange(new Rect(x, (h - size.Height) / 2, size.Width, size.Height)); x += size.Width; return(new Size(x, h)); }
protected override Size ArrangeOverride(Size finalSize) { Rect adornedElementRect = new Rect(this.AdornedElement.RenderSize); _contentPresenter.Arrange(new Rect(GetX(adornedElementRect, finalSize.Width), GetY(adornedElementRect, finalSize.Height), finalSize.Width, finalSize.Height)); return(_contentPresenter.RenderSize); }
public void Content_Alignment_And_Padding_Are_Applied_To_Child_Bounds( HorizontalAlignment h, VerticalAlignment v, double expectedX, double expectedY, double expectedWidth, double expectedHeight) { Border content; var target = new ContentPresenter { HorizontalContentAlignment = h, VerticalContentAlignment = v, Padding = new Thickness(10), Content = content = new Border { MinWidth = 16, MinHeight = 16, }, }; target.UpdateChild(); target.Measure(new Size(100, 100)); target.Arrange(new Rect(0, 0, 100, 100)); Assert.Equal(new Rect(expectedX, expectedY, expectedWidth, expectedHeight), content.Bounds); }
private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (!(d is TaskbarItemInfo info)) { return; } object?content = TaskbarItemInfoOverlay.GetContent(info); if (content == null) { info.Overlay = null; return; } UIElement element = new ContentPresenter { Content = content, ContentTemplate = TaskbarItemInfoOverlay.GetContentTemplate(info), ContentTemplateSelector = TaskbarItemInfoOverlay.GetContentTemplateSelector(info) }; element.Arrange(new Rect(0, 0, 16, 16)); RenderTargetBitmap bitmap = new RenderTargetBitmap(16, 16, 96, 96, PixelFormats.Pbgra32); bitmap.Render(element); bitmap.Freeze(); info.Overlay = bitmap; }
private void ArrangeLabel(ContentPresenter label, Size finalSize, double currentTickAngle, double radiusScale) { Size desiredSize = label.DesiredSize; double radius = Math.Min(finalSize.Width, finalSize.Height) / 2; Point center = GetIndicatorOffset(desiredSize, finalSize); var gauge = this.OwnerGauge as RadRadialGauge; double angle = 0; if (this.sweepDir == SweepDirection.Clockwise) { angle = RadialGaugePanel.ConvertDegreesToRadians(gauge.MinAngle) + RadialGaugePanel.ConvertDegreesToRadians(currentTickAngle); } else { angle = RadialGaugePanel.ConvertDegreesToRadians(gauge.MaxAngle) - RadialGaugePanel.ConvertDegreesToRadians(currentTickAngle); } Point labelPosition = CreateRotatedPoint(angle, radius, center, radiusScale); if ((TickType)label.GetValue(RadGauge.TickTypeProperty) == TickType.Label) { labelPosition.X -= desiredSize.Width * Math.Cos(angle) / 3; } label.Arrange(new Rect(labelPosition, desiredSize)); }
protected override Size ArrangeOverride(Size finalSize) { var rect = new Rect(Margin.Left, Margin.Top, finalSize.Width - (Margin.Left + Margin.Right), finalSize.Height - (Margin.Top + Margin.Bottom)); preserenter.Arrange(rect); return(finalSize); }
private void ArrangeTick(ContentPresenter tick, double value) { double halfTickHeight = tick.DesiredSize.Height / 2; double halfTickWidth = tick.DesiredSize.Width / 2; double minMaxDiff = Math.Abs(this.OwnerGauge.MaxValue - this.OwnerGauge.MinValue); double distance = RadGauge.MapLogicalToPhysicalValue(value, this.availableExtent, minMaxDiff); if (this.OwnerGauge.MaxValue < this.OwnerGauge.MinValue) { distance = this.availableExtent - distance; } double left = 0; double top = 0; if (this.isHorizontal) { tick.RenderTransform = null; left = distance - halfTickWidth; top = this.halfAvailableHeight - halfTickHeight; } else { tick.RenderTransform = this.verticalTickTransform; tick.RenderTransformOrigin = new Point(0.5, 0.5); left = this.halfAvailableWidth - halfTickWidth; top = this.availableExtent - distance - halfTickHeight; } tick.Arrange(new Rect(new Point(left, top), tick.DesiredSize)); }
protected override Size ArrangeOverride(Size finalSize) { lock (_syncpoint) { _contentPresenter.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height)); return(_contentPresenter.RenderSize); } }
protected override Size ArrangeOverride(Size finalSize) { if (!AdornedElement.IsVisible) { return(new Size(0, 0)); } _contentPresenter.Arrange(new Rect(finalSize)); return(finalSize); }
protected override Size ArrangeOverride(Size finalSize) { if (_internalHostPresenter == null) { return(base.ArrangeOverride(finalSize)); } _internalHostPresenter.Arrange(new Rect(finalSize)); return(base.ArrangeOverride(finalSize)); // new Size(_internalHostPresenter.ActualWidth, _internalHostPresenter.ActualHeight); }
protected override Size ArrangeOverride(Size finalSize) { if (left != null) { left.Arrange(new Rect(new Point(), finalSize)); middle.Arrange(new Rect(new Point(), finalSize)); right.Arrange(new Rect(new Point(), finalSize)); } SetLefts(ScrollOffset, finalSize.Width); return(finalSize); }
private static void ResetVisualState(ContentPresenter objectToPrint, PrintCapabilities printCaps) { objectToPrint.Width = double.NaN; objectToPrint.UpdateLayout(); objectToPrint.LayoutTransform = new ScaleTransform(1, 1); Size size = new Size(printCaps.PageImageableArea.ExtentWidth, printCaps.PageImageableArea.ExtentHeight); objectToPrint.Measure(size); objectToPrint.Arrange(new Rect(new Point(printCaps.PageImageableArea.OriginWidth, printCaps.PageImageableArea.OriginHeight), size)); }
ContentPresenter PagePresenterFromRestItems() { var restItems = new ArraySegment <TItem>(allItems, index, allItems.Length - index); var presenter = new ContentPresenter() { Content = printable.CreatePage(restItems, pageIndex, pageCount: 1), Width = pageSize.Width, Height = pageSize.Height, }; presenter.Measure(pageSize); presenter.Arrange(new Rect(new Point(0, 0), pageSize)); presenter.UpdateLayout(); return(presenter); }
public void Content_Can_Be_Stretched() { Border content; var target = new ContentPresenter { Content = content = new Border { MinWidth = 16, MinHeight = 16, }, }; target.UpdateChild(); target.Measure(new Size(100, 100)); target.Arrange(new Rect(0, 0, 100, 100)); Assert.Equal(new Rect(0, 0, 100, 100), content.Bounds); }
public void Content_Can_Be_Right_Aligned() { Border content; var target = new ContentPresenter { Content = content = new Border { MinWidth = 16, MinHeight = 16, HorizontalAlignment = HorizontalAlignment.Right }, }; target.UpdateChild(); target.Measure(new Size(100, 100)); target.Arrange(new Rect(0, 0, 100, 100)); Assert.Equal(new Rect(84, 0, 16, 100), content.Bounds); }
public void Content_Can_Be_Bottom_Aligned() { Border content; var target = new ContentPresenter { Content = content = new Border { MinWidth = 16, MinHeight = 16, VerticalAlignment = VerticalAlignment.Bottom, }, }; target.UpdateChild(); target.Measure(new Size(100, 100)); target.Arrange(new Rect(0, 0, 100, 100)); Assert.Equal(new Rect(0, 84, 100, 16), content.Bounds); }
protected override Size ArrangeOverride(Size finalSize) { Point point = Positon; point.X += Xoffset; point.Y += Yoffset; if (point.X + _contentPresenter.DesiredSize.Width > finalSize.Width) { point.X = finalSize.Width - _contentPresenter.DesiredSize.Width; } else if (point.X < 0) { point.X = 0; } _contentPresenter.Arrange(new Rect(point, _contentPresenter.DesiredSize)); return(finalSize); }
private void ArrangeCollapseElement(int idx, ContentPresenter element, double panelCenterX, double panelCenterY, double elementCenterX, double elementCenterY, double destX, double destY) { element.Arrange(new Rect(destX, destY, element.DesiredSize.Width, element.DesiredSize.Height)); var transGroup = element.RenderTransform as TransformGroup; Transform translateTransform, rotateTransform; if (transGroup == null) { element.RenderTransform = transGroup = new TransformGroup(); translateTransform = new TranslateTransform(); rotateTransform = new RotateTransform() { CenterX = elementCenterX, CenterY = elementCenterY }; transGroup.Children.Add(translateTransform); transGroup.Children.Add(rotateTransform); } else { translateTransform = transGroup.Children[0] as TranslateTransform; rotateTransform = transGroup.Children[1] as RotateTransform; } element.RenderTransformOrigin = new Point(0.5, 0.5); //if (i != 0) continue; var aniDuration = AnimationDuration + TimeSpan.FromSeconds(AnimationDurationStep * idx); translateTransform.BeginAnimation(TranslateTransform.XProperty, new DoubleAnimation(0, panelCenterX - destX, aniDuration)); translateTransform.BeginAnimation(TranslateTransform.YProperty, new DoubleAnimation(0, panelCenterY - destY, aniDuration)); rotateTransform.BeginAnimation(RotateTransform.CenterXProperty, new DoubleAnimation(0, panelCenterX - destX, aniDuration)); rotateTransform.BeginAnimation(RotateTransform.CenterYProperty, new DoubleAnimation(0, panelCenterY - destY, aniDuration)); rotateTransform.BeginAnimation(RotateTransform.AngleProperty, new DoubleAnimation(0, -720, aniDuration)); element.BeginAnimation(OpacityProperty, new DoubleAnimation(1, 0.2, aniDuration)); }
private void OnClosing(object sender, CancelEventArgs e) { if (!IsResultOk) { return; } foreach (var item in IconsList.FindVisualChildren <FrameworkElement>().Where(x => x.Name == @"NewIcon")) { if (!(item.DataContext is AppWindowItem data) || !data.IsInEditMode) { continue; } item.DataContext = data; data.Save(); var size = new Size(CommonAcConsts.AppIconWidth, CommonAcConsts.AppIconHeight); var result = new ContentPresenter { Width = size.Width, Height = size.Height, Content = item }; SaveIcon(); data.ShowEnabled = !data.ShowEnabled; SaveIcon(); void SaveIcon() { result.Measure(size); result.Arrange(new Rect(size)); result.ApplyTemplate(); result.UpdateLayout(); var bmp = new RenderTargetBitmap(CommonAcConsts.AppIconWidth, CommonAcConsts.AppIconHeight, 96, 96, PixelFormats.Pbgra32); bmp.Render(result); bmp.SaveTo(data.IconOriginal); BetterImage.Refresh(data.IconOriginal); } } }
/// <summary> /// Positions child elements and determines a size for the <see cref="FractionView"/>. /// </summary> /// <param name="arrangeBounds">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 arrangeBounds) { var frac = this.Fraction; if (frac != null && frac.Style == FractionStyle.Slanted) { rectN = new Rect(0.0, 0.0, sizeN.Width, sizeN.Height); rectD = new Rect(sizeTotal.Width - sizeD.Width, sizeTotal.Height - sizeD.Height, sizeD.Width, sizeD.Height); } else { rectN = new Rect((sizeTotal.Width - sizeN.Width) / 2.0, 0.0, sizeN.Width, sizeN.Height); rectD = new Rect((sizeTotal.Width - sizeD.Width) / 2.0, sizeN.Height, sizeD.Width, sizeD.Height); } NumeratorView.Arrange(rectN); DenominatorView.Arrange(rectD); if (frac == null) { return(sizeTotal); } switch (frac.Style) { case FractionStyle.Default: Line.Arrange(new Rect(new Point(), sizeTotal)); break; case FractionStyle.Slanted: Line.Arrange(new Rect(new Point(), sizeTotal)); break; case FractionStyle.Binomial: // TODO @ FractionView: Add braces (...). break; } return(sizeTotal); }
private static void ResetVisualState(ContentPresenter objectToPrint, PrintCapabilities printCaps, bool wasVirtualized) { objectToPrint.Width = double.NaN; objectToPrint.UpdateLayout(); objectToPrint.LayoutTransform = new ScaleTransform(1, 1); Size size = new Size(printCaps.PageImageableArea.ExtentWidth, printCaps.PageImageableArea.ExtentHeight); objectToPrint.Measure(size); objectToPrint.Arrange(new Rect(new Point(printCaps.PageImageableArea.OriginWidth, printCaps.PageImageableArea.OriginHeight), size)); if (!wasVirtualized) { return; } var dg = objectToPrint.FindChild <DataGrid>(); dg.EnableRowVirtualization = true; dg.EnableColumnVirtualization = true; VirtualizingPanel.SetIsVirtualizing(dg, true); }
public void Should_Correctly_Align_Child_With_Fixed_Size() { Border content; var target = new ContentPresenter { HorizontalContentAlignment = HorizontalAlignment.Stretch, VerticalContentAlignment = VerticalAlignment.Stretch, Content = content = new Border { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Bottom, Width = 16, Height = 16, }, }; target.UpdateChild(); target.Measure(new Size(100, 100)); target.Arrange(new Rect(0, 0, 100, 100)); // Check correct result for Issue #1447. Assert.Equal(new Rect(0, 84, 16, 16), content.Bounds); }
public void Child_Arrange_With_Zero_Height_When_Padding_Height_Greater_Than_Child_Height() { Border content; var target = new ContentPresenter { Padding = new Thickness(32), MaxHeight = 32, MaxWidth = 32, HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center, Content = content = new Border { Height = 0, Width = 0, }, }; target.UpdateChild(); target.Arrange(new Rect(0, 0, 100, 100)); Assert.Equal(new Rect(32, 32, 0, 0), content.Bounds); }
/// <summary> /// Positions child elements and determines a size for the <see cref="SubAndSuperscriptView"/>. /// </summary> /// <param name="arrangeBounds">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 arrangeBounds) { var dW = this.FontSize * 0.1; var hS = sizeSb.Height + sizeSp.Height; if (hS > sizeE.Height) { rectE = new Rect(new Point(0.0, (hS - sizeE.Height) / 2.0), sizeE); rectSb = new Rect(new Point(sizeE.Width + dW, hS / 2.0), sizeSb); rectSp = new Rect(new Point(sizeE.Width + dW, 0.0), sizeSp); } else { rectE = new Rect(new Point(0.0, 0.0), sizeE); rectSb = new Rect(new Point(sizeE.Width + dW, sizeE.Height - sizeSb.Height), sizeSb); rectSp = new Rect(new Point(sizeE.Width + dW, 0.0), sizeSp); } ExpressionView.Arrange(rectE); SubscriptView.Arrange(rectSb); SuperscriptView.Arrange(rectSp); return(sizeTotal); }
private static PrintCapabilities ScaleToFit1Page(ContentPresenter content, PrintDialog dlg, out double scale, double printScaleOffset) { var prCaps = dlg.PrintQueue.GetPrintCapabilities(dlg.PrintTicket); //get scale of the print wrt to screen of WPF visual scale = Math.Min(prCaps.PageImageableArea.ExtentWidth / content.ActualWidth, prCaps.PageImageableArea.ExtentHeight / content.ActualHeight); scale += printScaleOffset; //Transform the Visual to scale content.LayoutTransform = new ScaleTransform(scale, scale); //get the size of the printer page Size sz = new Size(prCaps.PageImageableArea.ExtentWidth, prCaps.PageImageableArea.ExtentHeight); //update the layout of the visual to the printer page size. content.Measure(sz); content.Arrange(new Rect(new Point(prCaps.PageImageableArea.OriginWidth, prCaps.PageImageableArea.OriginHeight), sz)); return(prCaps); }
protected override Size ArrangeOverride(Size finalSize) { contentPresenter.Arrange(new Rect(finalSize)); return(finalSize); }
protected override Size ArrangeOverride(Size finalSize) { _ContentPresenter.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height)); return(base.ArrangeOverride(finalSize)); }
/// <summary> /// Update the position and border of the tracker. /// </summary> private void UpdatePositionAndBorder() { if (contentContainer == null) { return; } var pos = this.Position; var lineExtents = this.LineExtents; Canvas.SetLeft(this, pos.X); Canvas.SetTop(this, pos.Y); Control parent = this; while (!(parent is Canvas) && parent != null) { parent = parent.GetVisualParent() as Control; } if (parent == null) { return; } // throw new InvalidOperationException("The TrackerControl must have a Canvas parent."); var canvasWidth = parent.Bounds.Width; var canvasHeight = parent.Bounds.Height; content.Measure(new Size(canvasWidth, canvasHeight)); content.Arrange(new Rect(0, 0, content.DesiredSize.Width, content.DesiredSize.Height)); var contentWidth = content.DesiredSize.Width; var contentHeight = content.DesiredSize.Height; // Minimum allowed margins around the tracker const double MarginLimit = 10; var ha = HorizontalAlignment.Center; if (CanCenterHorizontally) { if (pos.X - (contentWidth / 2) < MarginLimit) { ha = HorizontalAlignment.Left; } if (pos.X + (contentWidth / 2) > canvasWidth - MarginLimit) { ha = HorizontalAlignment.Right; } } else { ha = pos.X < canvasWidth / 2 ? HorizontalAlignment.Left : HorizontalAlignment.Right; } var va = VerticalAlignment.Center; if (CanCenterVertically) { if (pos.Y - (contentHeight / 2) < MarginLimit) { va = VerticalAlignment.Top; } if (ha == HorizontalAlignment.Center) { va = VerticalAlignment.Bottom; if (pos.Y - contentHeight < MarginLimit) { va = VerticalAlignment.Top; } } if (va == VerticalAlignment.Center && pos.Y + (contentHeight / 2) > canvasHeight - MarginLimit) { va = VerticalAlignment.Bottom; } if (va == VerticalAlignment.Top && pos.Y + contentHeight > canvasHeight - MarginLimit) { va = VerticalAlignment.Bottom; } } else { va = pos.Y < canvasHeight / 2 ? VerticalAlignment.Top : VerticalAlignment.Bottom; } var dx = ha == HorizontalAlignment.Center ? -0.5 : ha == HorizontalAlignment.Left ? 0 : -1; var dy = va == VerticalAlignment.Center ? -0.5 : va == VerticalAlignment.Top ? 0 : -1; path.Data = ShowPointer ? CreatePointerBorderGeometry(ha, va, contentWidth, contentHeight, out var margin) : CreateBorderGeometry(ha, va, contentWidth, contentHeight, out margin); content.Margin = margin; contentContainer.Measure(new Size(canvasWidth, canvasHeight)); var contentSize = contentContainer.DesiredSize; contentContainer.RenderTransform = new TranslateTransform { X = dx * contentSize.Width, Y = dy * contentSize.Height }; if (horizontalLine != null) { horizontalLine.StartPoint = new Point(lineExtents.Left - pos.X, 0); horizontalLine.EndPoint = new Point(lineExtents.Right - pos.X, 0); } if (verticalLine != null) { verticalLine.StartPoint = new Point(0, lineExtents.Top - pos.Y); verticalLine.EndPoint = new Point(0, lineExtents.Bottom - pos.Y); } }
public IEnumerable <OrderFormPage> PaginateCore(Size size) { // ページネーションを行うために、実際に DataGrid を生成する。 var preview = new OrderFormPage(Header, Items); var presenter = new ContentPresenter() { Content = preview, Width = size.Width, Height = size.Height, }; presenter.Measure(size); presenter.Arrange(new Rect(new Point(0, 0), size)); presenter.UpdateLayout(); var headeredGrid = presenter.VisualDescendantsBreadthFirstOrder().OfType <HeaderedGrid>().First(); var scrollViewer = headeredGrid.ScrollViewer; var grid = headeredGrid.Grid; var items = preview.Items; var index = 0; while (index < items.Count) { // 表示されている行数を計算する。 var totalRowHeight = grid.RowDefinitions[0].ActualHeight; var count = 0; while (index + count < items.Count) { totalRowHeight += grid.RowDefinitions[1 + index + count].ActualHeight; if (totalRowHeight > scrollViewer.ViewportHeight) { break; } count++; } if (count == 0) { // ヘッダー行が大きすぎてコンテンツを表示できていない。 throw new Exception(); } var pageItems = Enumerable.Range(index, count).Select(i => items[i]).ToArray(); // 1画面に表示できた行からなるページを追加する。 yield return(new OrderFormPage(Header, pageItems)); if (index + count < items.Count) { // いまのページに追加された分の行を非表示 (高さ 0) にする。 foreach (var i in Enumerable.Range(index, count)) { grid.RowDefinitions[1 + i].MaxHeight = 0.0; } // scrollViewer.ViewportHeight を更新する。 presenter.UpdateLayout(); } index += count; } }