protected virtual void InvalidatePosition(FrameworkElement child) { if (viewport == null) return; var transform = GetTransform(availableSize); Size elementSize = GetElementSize(child, AvailableSize, transform); child.Measure(elementSize); Rect bounds = GetElementScreenBounds(transform, child); if (!bounds.IsNaN()) { child.Arrange(bounds); } }
protected virtual void ArrangeTemplateControl() { if (_templateControl == null) { return; } PointF position = new PointF(_innerRect.X, _innerRect.Y); SizeF availableSize = new SizeF(_innerRect.Width, _innerRect.Height); ArrangeChild(_templateControl, HorizontalContentAlignment, VerticalContentAlignment, ref position, ref availableSize); RectangleF childRect = new RectangleF(position, availableSize); _templateControl.Arrange(childRect); }
protected override void OnApplyTemplate() #endif { base.OnApplyTemplate(); if (Template == null) { return; } _linePathObject = GetTemplatePart("PART_edgePath") as Path; if (_linePathObject == null) { throw new GX_ObjectNotFoundException("EdgeControl Template -> Edge template must contain 'PART_edgePath' Path object to draw route points!"); } _linePathObject.Data = _linegeometry; if (this.FindDescendantByName("PART_edgeArrowPath") != null) { throw new GX_ObsoleteException("PART_edgeArrowPath is obsolete! Please use new DefaultEdgePointer object in your EdgeControl template!"); } _edgeLabelControl = GetTemplatePart("PART_edgeLabel") as IEdgeLabelControl; _edgePointerForSource = GetTemplatePart("PART_EdgePointerForSource") as IEdgePointer; _edgePointerForTarget = GetTemplatePart("PART_EdgePointerForTarget") as IEdgePointer; SelfLoopIndicator = GetTemplatePart("PART_SelfLoopedEdge") as FrameworkElement; if (SelfLoopIndicator != null) { SelfLoopIndicator.LayoutUpdated += (sender, args) => { if (SelfLoopIndicator != null) { SelfLoopIndicator.Arrange(_selfLoopedEdgeLastKnownRect); } } } ; MeasureChild(_edgePointerForSource as UIElement); MeasureChild(_edgePointerForTarget as UIElement); MeasureChild(SelfLoopIndicator); //TODO measure label? UpdateSelfLoopedEdgeData(); UpdateEdge(); }
private static void ArrangeElement(FrameworkElement element, Size parentSize) { var rect = new Rect(new Point(), element.DesiredSize); switch (element.HorizontalAlignment) { case HorizontalAlignment.Center: rect.X = (parentSize.Width - rect.Width) / 2d; break; case HorizontalAlignment.Right: rect.X = parentSize.Width - rect.Width; break; case HorizontalAlignment.Stretch: rect.Width = parentSize.Width; break; default: break; } switch (element.VerticalAlignment) { case VerticalAlignment.Center: rect.Y = (parentSize.Height - rect.Height) / 2d; break; case VerticalAlignment.Bottom: rect.Y = parentSize.Height - rect.Height; break; case VerticalAlignment.Stretch: rect.Height = parentSize.Height; break; default: break; } if (element.UseLayoutRounding) { rect.X = Math.Round(rect.X); rect.Y = Math.Round(rect.Y); } element.Arrange(rect); }
protected override System.Windows.Size ArrangeOverride(System.Windows.Size finalSize) { if (InternalChildren.Count == 0) { return(base.ArrangeOverride(finalSize)); } FrameworkElement child = (FrameworkElement)InternalChildren [0]; WSize childSize = child.DesiredSize; // The child has to fill all the available space in the ScrollView // if the ScrollView happens to be bigger than the space required by the child if (childSize.Height < finalSize.Height) { childSize.Height = finalSize.Height; } if (childSize.Width < finalSize.Width) { childSize.Width = finalSize.Width; } if (!usingCustomScrolling) { // The viewport and extent doesn't have to be set when using custom scrolling, since they // are fully controlled by the child widget through the scroll adjustments if (this.extent != childSize) { this.extent = childSize; ScrollOwner.InvalidateScrollInfo(); } if (this.viewport != finalSize) { this.viewport = finalSize; ScrollOwner.InvalidateScrollInfo(); } } child.Arrange(new Rect(0, 0, childSize.Width, childSize.Height)); child.UpdateLayout(); if (child is IWpfWidget) { ((IWidgetSurface)(((IWpfWidget)child).Backend.Frontend)).Reallocate(); } return(finalSize); }
public static FixedDocument GetFixedDocument(FrameworkElement toPrint, PrintDialog printDialog, Thickness margin) { PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket); printDialog.PrintTicket.PageOrientation = PageOrientation.Landscape; Size pageSize = new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight); //Size pageSize = new Size(toPrint.ActualWidth, toPrint.ActualHeight); //Size visibleSize = new Size(capabilities.PageImageableArea.ExtentWidth - margin.Left - margin.Right, capabilities.PageImageableArea.ExtentHeight - margin.Top - margin.Bottom); Size visibleSize = new Size(toPrint.ActualWidth, toPrint.ActualHeight); FixedDocument fixedDoc = new FixedDocument(); //If the toPrint visual is not displayed on screen we neeed to measure and arrange it toPrint.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); toPrint.Arrange(new Rect(new Point(0, 0), toPrint.DesiredSize)); // Size size = toPrint.DesiredSize; //Will assume for simplicity the control fits horizontally on the page double yOffset = 0; while (yOffset < size.Height) { VisualBrush vb = new VisualBrush(toPrint); vb.Stretch = Stretch.None; vb.AlignmentX = AlignmentX.Left; vb.AlignmentY = AlignmentY.Top; vb.ViewboxUnits = BrushMappingMode.Absolute; vb.TileMode = TileMode.None; vb.Viewbox = new Rect(0, yOffset, visibleSize.Width, visibleSize.Height); PageContent pageContent = new PageContent(); FixedPage page = new FixedPage(); ((IAddChild)pageContent).AddChild(page); fixedDoc.Pages.Add(pageContent); page.Width = pageSize.Width; page.Height = pageSize.Height; Canvas canvas = new Canvas(); FixedPage.SetLeft(canvas, capabilities.PageImageableArea.OriginWidth); FixedPage.SetTop(canvas, capabilities.PageImageableArea.OriginHeight); canvas.Width = visibleSize.Width; canvas.Height = visibleSize.Height; canvas.Background = vb; canvas.Margin = margin; page.Children.Add(canvas); yOffset += visibleSize.Height; } return(fixedDoc); }
private void ArrangeElement(FrameworkElement element, BoundingBox boundingBox) { var projection = parentMap.MapProjection; var rect = projection.BoundingBoxToRect(boundingBox); var center = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d); var pos = parentMap.ViewTransform.MapToView(center); if (projection.IsNormalCylindrical && (pos.X < 0d || pos.X > parentMap.RenderSize.Width || pos.Y < 0d || pos.Y > parentMap.RenderSize.Height)) { var location = projection.MapToLocation(center); location.Longitude = Location.NearestLongitude(location.Longitude, parentMap.Center.Longitude); pos = parentMap.LocationToView(location); } rect.Width *= parentMap.ViewTransform.Scale; rect.Height *= parentMap.ViewTransform.Scale; rect.X = pos.X - rect.Width / 2d; rect.Y = pos.Y - rect.Height / 2d; if (element.UseLayoutRounding) { rect.X = Math.Round(rect.X); rect.Y = Math.Round(rect.Y); } element.Width = rect.Width; element.Height = rect.Height; element.Arrange(rect); var rotateTransform = element.RenderTransform as RotateTransform; var rotation = parentMap.ViewTransform.Rotation; if (rotateTransform != null) { rotateTransform.Angle = rotation; } else if (rotation != 0d) { rotateTransform = new RotateTransform { Angle = rotation }; element.RenderTransform = rotateTransform; element.RenderTransformOrigin = new Point(0.5, 0.5); } }
//FrameworkElement public static Cursor ToCursor(this FrameworkElement element, PointWpf hotSpot) {// size changed? color changed? var width = element.Width; var height = element.Height; element.Arrange(new Rect(new SizeWpf(width, height))); // Render to a bitmapSource var bitmapSource = new RenderTargetBitmap((int)width, (int)height, 96, 96, PixelFormatsWpf.Pbgra32); bitmapSource.Render(element); var bitmap = bitmapSource.ToBitmap(); return(bitmap.ToCursor(hotSpot)); }
private void AddFooter(ContainerVisual printedPage) { if (HasFooter) { DataTemplate dtFooter = OSEUIResources.Resources["DocumentFooter"] as DataTemplate; FrameworkElement ffe = dtFooter.LoadContent() as FrameworkElement; ffe.DataContext = this; ffe.Measure(_footerBox.Size); ffe.Arrange(_footerBox); ffe.UpdateLayout(); ContainerVisual footerContainer = new ContainerVisual(); footerContainer.Offset = new Vector(_footerBox.Left, _footerBox.Top); footerContainer.Children.Add(ffe); printedPage.Children.Add(footerContainer); } }
/// <inheritdoc/> protected override Size ArrangeOverride(Size finalSize) { if (_mainUiElement == null) { return(Size.Empty); } double width = _mainUiElement.Width; double height = _mainUiElement.Height; double x = GetRelativeXBasedOnTerminalDirection(width); double y = GetRelativeYBasedOnTerminalDirection(height); _mainUiElement.Arrange(new Rect(x, y, width, height)); 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) { if (_children.ItemsCount == 0) { return(finalSize); } double width = finalSize.Width; double top = 0; bool isFirst = true; if (_firstItemIndex < 0) { Debug.Assert(false, "First visible item should be specified before arrangement."); SetFirstVisibleItem(0, 0); SetVerticalOffset(0, false); } for (int index = _firstItemIndex; index < _children.ItemsCount; index++) { FrameworkElement element = _children.GetElement(index); if (element != null) { double height = element.DesiredSize.Height; if (isFirst) { // First visible item can be clipped top = -height * _firstItemClippedRatio; isFirst = false; } element.Arrange(new Rect(0, top, width, height)); top += height; if (top >= finalSize.Height) { // Out of view break; } } } return(finalSize); }
/// <summary> /// Print element to a document /// </summary> /// <param name="element">GUI Element to Print</param> /// <param name="dialog">Reference to Print Dialog</param> /// <param name="orientation">Page Orientation (i.e. Portrait vs. Landscape)</param> /// <returns>Destination document</returns> static FixedDocument ToFixedDocument(FrameworkElement element, PrintDialog dialog, PageOrientation orientation = PageOrientation.Portrait, UIElement header = null) { dialog.PrintTicket.PageOrientation = orientation; PrintCapabilities capabilities = dialog.PrintQueue.GetPrintCapabilities(dialog.PrintTicket); Size pageSize = new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight); Size extentSize = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight); FixedDocument fixedDocument = new FixedDocument(); element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); element.Arrange(new Rect(new Point(0, 0), element.DesiredSize)); for (double y = 0; y < element.DesiredSize.Height; y += extentSize.Height) { for (double x = 0; x < element.DesiredSize.Width; x += extentSize.Width) { VisualBrush brush = new VisualBrush(element); brush.Stretch = Stretch.None; brush.AlignmentX = AlignmentX.Left; brush.AlignmentY = AlignmentY.Top; brush.ViewboxUnits = BrushMappingMode.Absolute; brush.TileMode = TileMode.None; brush.Viewbox = new Rect(x, y, extentSize.Width, extentSize.Height); PageContent pageContent = new PageContent(); FixedPage page = new FixedPage(); ((IAddChild)pageContent).AddChild(page); fixedDocument.Pages.Add(pageContent); page.Width = pageSize.Width; page.Height = pageSize.Height; Canvas canvas = new Canvas(); FixedPage.SetLeft(canvas, capabilities.PageImageableArea.OriginWidth); FixedPage.SetTop(canvas, capabilities.PageImageableArea.OriginHeight); canvas.Width = extentSize.Width; canvas.Height = extentSize.Height; canvas.Background = brush; if (header != null) { page.Children.Add(header); } page.Children.Add(canvas); } } return(fixedDocument); }
public static FixedDocument ToFixedDocument(FrameworkElement element, PrintDialog dialog) { var capabilities = dialog.PrintQueue.GetPrintCapabilities(dialog.PrintTicket); var pageSize = new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight); var extentSize = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight); var fixedDocument = new FixedDocument(); element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); element.Arrange(new Rect(new Point(0, 0), element.DesiredSize)); var totalHeight = element.DesiredSize.Height; var yOffset = 0d; while (yOffset < totalHeight) { var brush = new VisualBrush(element) { Stretch = Stretch.None, AlignmentX = AlignmentX.Left, AlignmentY = AlignmentY.Top, ViewboxUnits = BrushMappingMode.Absolute, TileMode = TileMode.None, Viewbox = new Rect(0, yOffset, extentSize.Width, extentSize.Height) }; var pageContent = new PageContent(); var page = new FixedPage(); ((IAddChild)pageContent).AddChild(page); fixedDocument.Pages.Add(pageContent); page.Width = pageSize.Width; page.Height = pageSize.Height; var canvas = new Canvas(); FixedPage.SetLeft(canvas, capabilities.PageImageableArea.OriginWidth); FixedPage.SetTop(canvas, capabilities.PageImageableArea.OriginHeight); canvas.Width = extentSize.Width; canvas.Height = extentSize.Height; canvas.Background = brush; page.Children.Add(canvas); yOffset += extentSize.Height; } return(fixedDocument); }
/// <summary> /// Performs the Arrange pass of the layout. /// </summary> /// <remarks> /// We round rectangles to snap to nearest pixels. We do that to avoid /// anti-aliasing which results in better appearance. Moreover to get /// correct layout we would need to use UseLayoutRounding=false which /// is Silverlight specific. A side effect is that areas for rectangles /// in the visual tree no longer can be used to compare them as dimensions /// are not rounded and therefore not precise. /// </remarks> /// <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) { // Sets ActualHeight & ActualWidth for the container finalSize = base.ArrangeOverride(finalSize); if (_nodeRoots != null && ContainerElement != null) { // Create a temporary pseudo-root node containing all the top-level nodes TreeMapNode root = new TreeMapNode() { Area = _nodeRoots.Sum(x => x.Area), Children = _nodeRoots, ChildItemPadding = new Thickness(0) }; // Calculate associated rectangles. We use ContainerElement, // not finalSize so all elements that are above it like border // (with padding and border) are taken into account IEnumerable <Tuple <Rect, TreeMapNode> > measuredRectangles = ComputeRectangles( root, new Rect(0, 0, ContainerElement.ActualWidth, ContainerElement.ActualHeight)); // Position everything foreach (Tuple <Rect, TreeMapNode> rectangle in measuredRectangles) { FrameworkElement element = rectangle.Item2.Element; if (element != null) { double roundedTop = Math.Round(rectangle.Item1.Top); double roundedLeft = Math.Round(rectangle.Item1.Left); double height = Math.Round(rectangle.Item1.Height + rectangle.Item1.Top) - roundedTop; double width = Math.Round(rectangle.Item1.Width + rectangle.Item1.Left) - roundedLeft; // Fully specify element location/size (setting size is required on WPF) Canvas.SetLeft(element, roundedLeft); Canvas.SetTop(element, roundedTop); element.Width = width; element.Height = height; element.Arrange(new Rect(roundedLeft, roundedTop, width, height)); } } } return(finalSize); }
public static ImageSource ToImageSource(FrameworkElement obj) { Transform transform = obj.LayoutTransform; Thickness margin = obj.Margin; obj.Margin = new Thickness(0, 0, margin.Right - margin.Left, margin.Bottom - margin.Top); Size size = new Size(obj.ActualWidth, obj.ActualHeight); obj.Measure(size); obj.Arrange(new Rect(size)); RenderTargetBitmap bmp = new RenderTargetBitmap((int)obj.ActualWidth, (int)obj.ActualHeight, 96, 96, PixelFormats.Pbgra32); bmp.Render(obj); obj.LayoutTransform = transform; obj.Margin = margin; return(bmp); }
private void DrawToImage(FrameworkElement element) { element.Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity)); element.Arrange(new Rect(element.DesiredSize)); System.Windows.Media.Imaging.RenderTargetBitmap bitmap = new System.Windows.Media.Imaging.RenderTargetBitmap((int)element.ActualWidth, (int)element.ActualHeight, 120.0, 120.0, System.Windows.Media.PixelFormats.Pbgra32); bitmap.Render(element); System.Windows.Media.Imaging.BitmapEncoder encoder = new System.Windows.Media.Imaging.PngBitmapEncoder(); encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bitmap)); using (Stream s = File.OpenWrite(@"C:\555.png")) { encoder.Save(s); } }
internal override void ArrangeCell(GridCellModel cell) { FrameworkElement container = cell.Container as FrameworkElement; if (container == null) { return; } RadRect layoutSlot = cell.layoutSlot; var rect = this.Owner.InflateCellHorizontally(cell, layoutSlot); rect = this.Owner.InflateCellVertically(cell, rect); container.Arrange(rect.ToRect()); }
public static void Print(FrameworkElement visual) { PrintDialog dialog = new PrintDialog(); if (dialog.ShowDialog() == true) { System.Printing.PrintCapabilities capabilities = dialog.PrintQueue.GetPrintCapabilities(dialog.PrintTicket); double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / visual.ActualWidth, capabilities.PageImageableArea.ExtentHeight / visual.ActualHeight); Transform originalTransform = visual.LayoutTransform; visual.LayoutTransform = new ScaleTransform(scale, scale); Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight); visual.Measure(sz); visual.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz)); dialog.PrintVisual(visual, "Chart"); visual.LayoutTransform = originalTransform; } }
public override DocumentPage GetPage(int pageNumber) { Element.RenderTransform = new TranslateTransform(-PageSize.Width * (pageNumber % Columns), -PageSize.Height * (pageNumber / Columns)); Size elementSize = new Size( Element.ActualWidth, Element.ActualHeight); Element.Measure(elementSize); Element.Arrange(new Rect(new Point(0, 0), elementSize)); var page = new DocumentPage(Element); Element.RenderTransform = null; return(page); }
private void ModifyPosition(FrameworkElement fe) { /// get the size of the visual with margin Size fs = new Size( fe.ActualWidth + fe.Margin.Left + fe.Margin.Right, fe.ActualHeight + fe.Margin.Top + fe.Margin.Bottom); /// measure the visual with new size fe.Measure(fs); /// arrange the visual to align parent with (0,0) fe.Arrange(new Rect( -fe.Margin.Left, -fe.Margin.Top, fs.Width, fs.Height)); }
private void SaveUsingEncoder(FrameworkElement visual, string fileName, BitmapEncoder encoder) { RenderTargetBitmap bitmap = new RenderTargetBitmap((int)visual.ActualWidth, (int)visual.ActualHeight, 2, 2, PixelFormats.Pbgra32); Size visualSize = new Size(visual.ActualWidth, visual.ActualHeight); visual.Measure(visualSize); visual.Arrange(new Rect(visualSize)); bitmap.Render(visual); BitmapFrame frame = BitmapFrame.Create(bitmap); encoder.Frames.Add(frame); using (var stream = File.Create(fileName)) { encoder.Save(stream); } }
public static void SaveUsingEncoder(string fileName, FrameworkElement UIElement, BitmapEncoder encoder) { int height = (int)UIElement.ActualHeight; int width = (int)UIElement.ActualWidth; // These two line of code make sure that you get completed visual bitmap. // In case your Framework Element is inside the scroll viewer then some part which is not // visible gets clip. UIElement.Measure(new System.Windows.Size(width, height)); UIElement.Arrange(new Rect(new System.Windows.Point(), new Point(width, height))); RenderTargetBitmap bitmap = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32); bitmap.Render(UIElement); SaveUsingBitmapTargetRenderer(fileName, bitmap, encoder); }
protected virtual void ArrangeTemplateControl() { FrameworkElement templateControl = _templateControl; if (templateControl == null) { return; } PointF position = new PointF(_innerRect.X, _innerRect.Y); SizeF availableSize = new SizeF(_innerRect.Width, _innerRect.Height); ArrangeChild(templateControl, HorizontalContentAlignment, VerticalContentAlignment, ref position, ref availableSize); RectangleF childRect = SharpDXExtensions.CreateRectangleF(position, availableSize); templateControl.Arrange(childRect); }
// Saves the graph as a file with no extension, can be opened in paint, needs fixing if possible private void SaveGraphAsImage(FrameworkElement element) { var size = new Size(element.Width, element.Height); element.Measure(size); element.Arrange(new Rect(size)); var render = new RenderTargetBitmap((int)element.Width, (int)element.Height, 96d, 96d, PixelFormats.Default); render.Render(element); var encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(render)); using (var file = new FileStream("GraphOutput.png", FileMode.Create)) encoder.Save(file); }
// Performs Measure and Arrange steps, so that the element's ActualHeight and ActualWidth are properly calculated. Note that setting the alignment is required, otherwise // some elements will just grow indefinitely if they're left with Stretch as their alignment. public static void Measure(this FrameworkElement fe) { if (fe == null) { return; } VerticalAlignment oldV = fe.VerticalAlignment; HorizontalAlignment oldH = fe.HorizontalAlignment; fe.VerticalAlignment = VerticalAlignment.Top; fe.HorizontalAlignment = HorizontalAlignment.Left; fe.UpdateLayout(); fe.Measure(new Size(double.MaxValue, double.MaxValue)); fe.Arrange(new Rect(0.0, 0.0, double.MaxValue, double.MaxValue)); fe.VerticalAlignment = oldV; fe.HorizontalAlignment = oldH; }
public static FixedDocument GetFixedDocument(FrameworkElement toPrint, PrintDialog printDialog) { toPrint.FlowDirection = FlowDirection.RightToLeft; var capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket); var pageSize = new Size(printDialog.PrintableAreaHeight, printDialog.PrintableAreaWidth); var visibleSize = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight); var fixedDoc = new FixedDocument(); //If the toPrint visual is not displayed on screen we neeed to measure and arrange it toPrint.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); toPrint.Arrange(new Rect(new Point(0, 0), toPrint.DesiredSize)); // var size = toPrint.DesiredSize; //Will assume for simplicity the control fits horizontally on the page double yOffset = 0; while (yOffset < size.Height) { var vb = new VisualBrush(toPrint) { Stretch = Stretch.None, AlignmentX = AlignmentX.Left, AlignmentY = AlignmentY.Top, ViewboxUnits = BrushMappingMode.Absolute, TileMode = TileMode.None, Viewbox = new Rect(0, yOffset, visibleSize.Width, visibleSize.Height) }; var pageContent = new PageContent(); var page = new FixedPage(); ((IAddChild)pageContent).AddChild(page); fixedDoc.Pages.Add(pageContent); page.Width = pageSize.Width; page.Height = pageSize.Height; var canvas = new Canvas(); FixedPage.SetLeft(canvas, capabilities.PageImageableArea.OriginWidth); FixedPage.SetTop(canvas, capabilities.PageImageableArea.OriginHeight); canvas.Width = visibleSize.Width; canvas.Height = visibleSize.Height; canvas.Background = vb; page.Children.Add(canvas); yOffset += visibleSize.Height; } return(fixedDoc); }
static public void ExportPng(Uri path, FrameworkElement surface) { if (path == null) { return; } // Save current canvas transform Transform transform = surface.LayoutTransform; // reset current transform (in case it is scaled or rotated) surface.LayoutTransform = null; // Get the size of canvas Size size = new Size(surface.Width, surface.Height); // Measure and arrange the surface // VERY IMPORTANT surface.Measure(size); surface.Arrange(new Rect(size)); // Create a render bitmap and push the surface to it RenderTargetBitmap renderBitmap = new RenderTargetBitmap( (int)size.Width, (int)size.Height, 96d, 96d, PixelFormats.Bgra32); renderBitmap.Render(surface); // Create a file stream for saving image using (FileStream outStream = new FileStream(path.LocalPath, FileMode.Create)) { // Use png encoder for our data PngBitmapEncoder encoder = new PngBitmapEncoder(); // push the rendered bitmap to it encoder.Frames.Add(BitmapFrame.Create(renderBitmap)); // save the data to the stream encoder.Save(outStream); } // Restore previously saved layout surface.LayoutTransform = transform; }
/// <summary> /// Overrides the arrange method for this control, allowing content to be placed /// according to your own layout criteria. In this case we are going to lay /// all the child objects out along the edge of an ellipse. /// </summary> /// <param name="arrangeSize"></param> /// <returns></returns> protected override Size ArrangeOverride(Size arrangeSize) { //Work out the circumference of our Ellipse as this may have changed. double layoutCirfumference = CalculateEllipseCircumferenceRamanujan2(EllipseWidth, EllipseHeight); //Calculate the spacing between each item. double itemSpacing = layoutCirfumference / Children.Count; //Iterate the children. We could have used a foreach, but //as we need to know the index of the child we are working with, //this is cleaner. for (int i = 0; i < Children.Count; i++) { //We want the item as a FrameworkElement so that we can //get its height and width. FrameworkElement child = Children[i] as FrameworkElement; if (child == null) { continue; } //Work out how far around the ellipse we are double theta = (Math.PI * 2) * ((i * itemSpacing) / layoutCirfumference); //Offset so the ellipse starts at the top. theta -= Math.PI / 2; //Now to calculate the point on the edge of the ellipse for the current rotation. Point p = GetPointOnEllipse(EllipseWidth, EllipseHeight, new Point(EllipseCentreX, EllipseCentreY), theta); //Position the element SetLeft(child, p.X - child.DesiredSize.Width * 0.5); SetTop(child, p.Y - child.DesiredSize.Height * 0.5); //Get the child control to arrange itself. child.Arrange(new Rect(new Point(p.X, p.Y), child.DesiredSize)); } return(arrangeSize); }
/// <summary> /// Uses a WPF FrameworkElement to create a keyImage /// </summary> /// <param name="deck"></param> /// <param name="e"></param> /// <returns></returns> public static byte[] CreateKeyFromWpfElement(this Client deck, FrameworkElement e) { //Do WPF layout process manually (because the element is not a UI element) e.Measure(new Size(72, 72)); e.Arrange(new Rect(0, 0, 72, 72)); e.UpdateLayout(); //Render the element as bitmap RenderTargetBitmap renderer = new RenderTargetBitmap(72, 72, 96, 96, PixelFormats.Pbgra32); renderer.Render(e); //Convert to StreamDeck compatible format var pbgra32 = new byte[72 * 72 * 4]; renderer.CopyPixels(pbgra32, 72 * 4, 0); return(ConvertPbgra32ToStreamDeckKey(pbgra32)); }
public void AddVisualToCanvas(FrameworkElement visual, Body body) { if (body != null) { new BodyVisualHelper(visual, body); } //hasn't been rendered yet, so needs to work out it's size if (visual.ActualWidth == 0 && visual.ActualHeight == 0) { Debug.Assert(ActualWidth != 0 && ActualHeight != 0); visual.Arrange(new Rect(0, 0, ActualWidth, ActualHeight)); } Children.Add(visual); visual.IsHitTestVisible = true; }
protected override void OnApplyTemplate() #endif { base.OnApplyTemplate(); if (Template == null) return; _linePathObject = GetTemplatePart("PART_edgePath") as Path; if (_linePathObject == null) throw new GX_ObjectNotFoundException("EdgeControl Template -> Edge template must contain 'PART_edgePath' Path object to draw route points!"); _linePathObject.Data = _linegeometry; if (this.FindDescendantByName("PART_edgeArrowPath") != null) throw new GX_ObsoleteException("PART_edgeArrowPath is obsolete! Please use new DefaultEdgePointer object in your EdgeControl template!"); _edgeLabelControl = GetTemplatePart("PART_edgeLabel") as IEdgeLabelControl; _edgePointerForSource = GetTemplatePart("PART_EdgePointerForSource") as IEdgePointer; _edgePointerForTarget = GetTemplatePart("PART_EdgePointerForTarget") as IEdgePointer; SelfLoopIndicator = GetTemplatePart("PART_SelfLoopedEdge") as FrameworkElement; if(SelfLoopIndicator != null) SelfLoopIndicator.LayoutUpdated += (sender, args) => { if (SelfLoopIndicator != null) SelfLoopIndicator.Arrange(_selfLoopedEdgeLastKnownRect); }; MeasureChild(_edgePointerForSource as UIElement); MeasureChild(_edgePointerForTarget as UIElement); MeasureChild(SelfLoopIndicator); //TODO measure label? UpdateSelfLoopedEdgeData(); UpdateEdge(); }