public void CreateBitmap() { int width = 100; int height = 100; int dpi = 96; Tracing.Log(">> CreateBitmap"); var thread = new Thread(new ThreadStart(() => { Tracing.Log(">> CreateBitmap - Thread start; creating drawing visual"); //Dispatcher.Invoke(new Action(() => { _drawingVisual = new DrawingVisual(); _drawingContext = _drawingVisual.RenderOpen(); //})); Tracing.Log(">> CreateBitmap - Drawing to context"); _drawingContext.DrawRectangle(new SolidColorBrush(Colors.HotPink), new Pen(), new Rect(0, 0, 50, 50)); _drawingContext.DrawRectangle(new SolidColorBrush(Colors.Blue), new Pen(), new Rect(50, 0, 50, 50)); _drawingContext.DrawRectangle(new SolidColorBrush(Colors.Orange), new Pen(), new Rect(0, 50, 50, 50)); _drawingContext.DrawRectangle(new SolidColorBrush(Colors.DarkRed), new Pen(), new Rect(50, 50, 50, 50)); _drawingContext.Close(); Tracing.Log(">> CreateBitmap - Finished drawing; creating render target bitmap"); _bitmap = new RenderTargetBitmap(width, height, dpi, dpi, PixelFormats.Default); _bitmap.Render(_drawingVisual); Tracing.Log(">> CreateBitmap - Finished work"); _bitmap.Freeze(); })); //thread.IsBackground = true; thread.SetApartmentState(ApartmentState.STA); thread.Start(); }
protected override void DrawTile(DrawingContext dc, Rect TileRect) { if (!_tileImage.IsReady) dc.DrawRectangle(Brushes.LemonChiffon, null, TileRect); else dc.DrawImage(_tileImage.Image, TileRect); }
protected override void OnRender(DrawingContext dc) { if (background != null) { dc.DrawImage(background, new Rect(0, 0, background.PixelWidth, background.PixelHeight)); } }
public void Draw(TextView textView, DrawingContext drawingContext) { if (textView == null) throw new ArgumentNullException("textView"); if (drawingContext == null) throw new ArgumentNullException("drawingContext"); if (currentResults == null || !textView.VisualLinesValid) return; var visualLines = textView.VisualLines; if (visualLines.Count == 0) return; int viewStart = visualLines.First().FirstDocumentLine.Offset; int viewEnd = visualLines.Last().LastDocumentLine.EndOffset; foreach (SearchResult result in currentResults.FindOverlappingSegments(viewStart, viewEnd - viewStart)) { BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder(); geoBuilder.AlignToMiddleOfPixels = true; geoBuilder.CornerRadius = 3; geoBuilder.AddSegment(textView, result); Geometry geometry = geoBuilder.CreateGeometry(); if (geometry != null) { drawingContext.DrawGeometry(markerBrush, markerPen, geometry); } } }
protected override void OnRender(DrawingContext drawingContext) { FoldingMargin margin = VisualParent as FoldingMargin; Pen activePen = new Pen(margin.SelectedFoldingMarkerBrush, 1); Pen inactivePen = new Pen(margin.FoldingMarkerBrush, 1); activePen.StartLineCap = inactivePen.StartLineCap = PenLineCap.Square; activePen.EndLineCap = inactivePen.EndLineCap = PenLineCap.Square; Size pixelSize = PixelSnapHelpers.GetPixelSize(this); Rect rect = new Rect(pixelSize.Width / 2, pixelSize.Height / 2, this.RenderSize.Width - pixelSize.Width, this.RenderSize.Height - pixelSize.Height); drawingContext.DrawRectangle( IsMouseDirectlyOver ? margin.SelectedFoldingMarkerBackgroundBrush : margin.FoldingMarkerBackgroundBrush, IsMouseDirectlyOver ? activePen : inactivePen, rect); double middleX = rect.Left + rect.Width / 2; double middleY = rect.Top + rect.Height / 2; double space = PixelSnapHelpers.Round(rect.Width / 8, pixelSize.Width) + pixelSize.Width; drawingContext.DrawLine(activePen, new Point(rect.Left + space, middleY), new Point(rect.Right - space, middleY)); if (!isExpanded) { drawingContext.DrawLine(activePen, new Point(middleX, rect.Top + space), new Point(middleX, rect.Bottom - space)); } }
/// <summary> /// Draw object /// </summary> public override void Draw(DrawingContext drawingContext) { if ( drawingContext == null ) { throw new ArgumentNullException("drawingContext"); } Rect r = Rectangle; Point center = new Point( (r.Left + r.Right) / 2.0, (r.Top + r.Bottom) / 2.0); double radiusX = (r.Right - r.Left) / 2.0; double radiusY = (r.Bottom - r.Top) / 2.0; drawingContext.DrawEllipse( null, new Pen(new SolidColorBrush(ObjectColor), ActualLineWidth), center, radiusX, radiusY); base.Draw(drawingContext); }
/// <summary> /// Draws a bone line between two joints /// </summary> /// <param name="skeleton">skeleton to draw bones from</param> /// <param name="drawingContext">drawing context to draw to</param> /// <param name="jointType0">joint to start drawing from</param> /// <param name="jointType1">joint to end drawing at</param> public static void DrawBone(TSkeleton skeleton, DrawingContext drawingContext, TJointType jointType0, TJointType jointType1) { TJoint joint0 = skeleton.Joints[(int)jointType0]; TJoint joint1 = skeleton.Joints[(int)jointType1]; // If we can't find either of these joints, exit if (joint0.TrackingState == TJointTrackingState.NotTracked || joint1.TrackingState == TJointTrackingState.NotTracked) { return; } // Don't draw if both points are inferred if (joint0.TrackingState == TJointTrackingState.Inferred && joint1.TrackingState == TJointTrackingState.Inferred) { return; } // We assume all drawn bones are inferred unless BOTH joints are tracked Pen drawPen = inferredBonePen; if (joint0.TrackingState == TJointTrackingState.Tracked && joint1.TrackingState == TJointTrackingState.Tracked) { drawPen = trackedBonePen; } drawingContext.DrawLine(drawPen, SkeletonPointToScreen(joint0.Position), SkeletonPointToScreen(joint1.Position)); }
protected override void OnRenderCore(DrawingContext dc, RenderState state) { if (DataSource == null) return; var transform = Plotter2D.Viewport.Transform; Rect bounds = Rect.Empty; using (IPointEnumerator enumerator = DataSource.GetEnumerator(GetContext())) { Point point = new Point(); while (enumerator.MoveNext()) { enumerator.GetCurrent(ref point); enumerator.ApplyMappings(this); Point zero = new Point(point.X, 0); Point screenPoint = point.DataToScreen(transform); Point screenZero = zero.DataToScreen(transform); double height = screenPoint.Y = screenZero.Y; height = (height >= 0) ? height : -height; dc.DrawRectangle(Fill, new Pen(Stroke, StrokeThickness), new Rect(screenPoint.X - BarWidth / 2, screenZero.Y, BarWidth, height)); bounds = Rect.Union(bounds, point); } } ContentBounds = bounds; }
private static void RenderClippedEdges(Skeleton skeleton, DrawingContext drawingContext) { if (skeleton.ClippedEdges.HasFlag(FrameEdges.Bottom)) { drawingContext.DrawRectangle( Brushes.Red, null, new Rect(0, RenderHeight - ClipBoundsThickness, RenderWidth, ClipBoundsThickness)); } if (skeleton.ClippedEdges.HasFlag(FrameEdges.Top)) { drawingContext.DrawRectangle( Brushes.Red, null, new Rect(0, 0, RenderWidth, ClipBoundsThickness)); } if (skeleton.ClippedEdges.HasFlag(FrameEdges.Left)) { drawingContext.DrawRectangle( Brushes.Red, null, new Rect(0, 0, ClipBoundsThickness, RenderHeight)); } if (skeleton.ClippedEdges.HasFlag(FrameEdges.Right)) { drawingContext.DrawRectangle( Brushes.Red, null, new Rect(RenderWidth - ClipBoundsThickness, 0, ClipBoundsThickness, RenderHeight)); } }
protected override void OnRender(DrawingContext drawingContext) { double width = RenderSize.Width; double height = RenderSize.Height; MeshGeometry3D mesh = Mesh; if (mesh != null) { Pen pen = new Pen(Brushes.Black, 1.0); int numTriangles = mesh.TriangleIndices.Count/3; for(int i = 0; i < numTriangles; i++) { DrawTriangle(drawingContext, pen, mesh.TextureCoordinates[mesh.TriangleIndices[i * 3]], mesh.TextureCoordinates[mesh.TriangleIndices[i * 3 + 1]], mesh.TextureCoordinates[mesh.TriangleIndices[i * 3 + 2]], width, height); } } base.OnRender(drawingContext); }
protected override void OnRender(DrawingContext drawingContext) { Rect rect = new Rect(startPoint, endPoint); rect.Offset(-0.5d, -0.5d); drawingContext.DrawRectangle(fill, stroke, rect); }
protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); drawingContext.PushTransform(new TranslateTransform(AdornedElement.RenderSize.Width - 14, (AdornedElement.RenderSize.Height - 18) / 2.0)); drawingContext.DrawGeometry(ArrowBrush, null, sda_render_geometry); drawingContext.Pop(); }
/// <summary> /// Draw some helpful text. /// </summary> /// <param name="dc"></param> protected virtual void DrawHelpText(DrawingContext dc) { System.Windows.Media.Typeface backType = new System.Windows.Media.Typeface(new System.Windows.Media.FontFamily("sans courier"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); System.Windows.Media.FormattedText formatted = new System.Windows.Media.FormattedText( "Click & move the mouse to select a capture area.\nENTER/F10: Capture\nBACKSPACE/DEL: Start over\nESC: Exit", System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, backType, 32.0f, new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.White)); // Make sure the text shows at 0,0 on the primary screen System.Drawing.Point primScreen = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Location; Point clientBase = PointFromScreen(new Point(primScreen.X + 5, primScreen.Y + 5)); Geometry textGeo = formatted.BuildGeometry(clientBase); dc.DrawGeometry( System.Windows.Media.Brushes.White, null, textGeo); dc.DrawGeometry( null, new System.Windows.Media.Pen(System.Windows.Media.Brushes.White, 1), textGeo); }
private void DrawSearchHighlight(DrawingContext dc, Block block) { foreach (var pair in _curSearchMatches) { int txtOffset = 0; double y = block.Y; for (int i = 0; i < block.Text.Length; i++) { int start = Math.Max(txtOffset, pair.Item1); int end = Math.Min(txtOffset + block.Text[i].Length, pair.Item2); if (end > start) { double x1 = block.Text[i].GetDistanceFromCharacterHit(new CharacterHit(start, 0)) + block.TextX; double x2 = block.Text[i].GetDistanceFromCharacterHit(new CharacterHit(end, 0)) + block.TextX; dc.DrawRectangle(_searchBrush.Value, null, new Rect(new Point(x1, y), new Point(x2, y + _lineHeight))); } y += _lineHeight; txtOffset += block.Text[i].Length; } } }
protected virtual void PaintCovexHull(HandData cluster, DrawingContext drawingContext) { if (cluster.ConvexHull.Count > 3) { this.DrawLines(drawingContext, this.whitePen, cluster.ConvexHull.Points.Select(p => new System.Windows.Point(p.X, p.Y)).ToArray()); } }
private void DrawChanges(DrawingContext drawingContext, NormalizedSnapshotSpanCollection changes, Brush brush) { if (changes.Count > 0) { double yTop = Math.Floor(_scrollBar.GetYCoordinateOfBufferPosition(changes[0].Start)) + markerStartOffset; double yBottom = Math.Ceiling(_scrollBar.GetYCoordinateOfBufferPosition(changes[0].End)) + markerEndOffset; for (int i = 1; i < changes.Count; ++i) { double y = _scrollBar.GetYCoordinateOfBufferPosition(changes[i].Start) + markerStartOffset; if (yBottom < y) { drawingContext.DrawRectangle( brush, null, new Rect(0, yTop, markerWidth, yBottom - yTop)); yTop = y; } yBottom = Math.Ceiling(_scrollBar.GetYCoordinateOfBufferPosition(changes[i].End)) + markerEndOffset; } drawingContext.DrawRectangle( brush, null, new Rect(0, yTop, markerWidth, yBottom - yTop)); } }
/// <summary>Draws a snapped orthogonal line.</summary> internal static void DrawOrthogonal(DrawingContext dc, Orientation orientation, Pen pen, double q, double p0, double p1) { if (orientation == Orientation.Horizontal) { DrawHorizontal(dc, pen, q, p0, p1); } else { DrawVertical(dc, pen, q, p0, p1); } }
protected override void OnRender(DrawingContext drawingContext) { Size renderSize = this.RenderSize; TextView textView = this.TextView; if (textView != null && textView.VisualLinesValid) { foreach (VisualLine line in textView.VisualLines) { Rect rect = new Rect(0, line.VisualTop - textView.ScrollOffset.Y, 5, line.Height); LineChangeInfo info = changeWatcher.GetChange(line.FirstDocumentLine.LineNumber); switch (info.Change) { case ChangeType.None: break; case ChangeType.Added: drawingContext.DrawRectangle(Brushes.LightGreen, null, rect); break; case ChangeType.Deleted: case ChangeType.Modified: drawingContext.DrawRectangle(Brushes.LightBlue, null, rect); break; case ChangeType.Unsaved: drawingContext.DrawRectangle(Brushes.Yellow, null, rect); break; default: throw new Exception("Invalid value for ChangeType"); } } } }
private void Render(DrawingContext drawingContext) { if (_width > 0 && _height > 0) { if (_bitmap == null || _bitmap.Width != _width || _bitmap.Height != _height) { _bitmap = new WriteableBitmap(_width, _height, 96, 96, PixelFormats.Pbgra32, null); } _bitmap.Lock(); using (var surface = SKSurface.Create(_width, _height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, _bitmap.BackBuffer, _bitmap.BackBufferStride)) { var canvas = surface.Canvas; canvas.Scale((float)_dpiX, (float)_dpiY); canvas.Clear(); using (new SKAutoCanvasRestore(canvas, true)) { Presenter.Render(canvas, Renderer, Container, _offsetX, _offsetY); } } _bitmap.AddDirtyRect(new Int32Rect(0, 0, _width, _height)); _bitmap.Unlock(); drawingContext.DrawImage(_bitmap, new Rect(0, 0, _actualWidth, _actualHeight)); } }
/// <summary> /// OnRender override draws the geometry of the text and optional highlight. /// </summary> /// <param name="drawingContext">Drawing context of the OutlineText control.</param> protected override void OnRender(DrawingContext drawingContext) { CreateText(); // Draw the outline based on the properties that are set. drawingContext.DrawGeometry(Fill, new Pen(Stroke, StrokeThickness), _textGeometry); }
protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); DrawGrid(drawingContext); DrawChart(drawingContext); UpdateParent(); }
public override void Draw(DrawingContext dc) { if (HasConnection()) CoreDraw.DrawLine(dc, StartConn.getPort().getCenter(), EndConn.getPort().getCenter(), LineWidth, Brushes.Blue, CoreDraw.LineStyle_StraightLine); }
protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); double segmentStart; double segmentEnd; if (Edge.Orientation == Orientation.Vertical) { segmentStart = Math.Min(Edge.Range.SegmentStart, CanvasItem.Top); segmentEnd = Math.Max(Edge.Range.SegmentEnd, CanvasItem.Bottom); } else { segmentStart = Math.Min(Edge.Range.SegmentStart, CanvasItem.Left); segmentEnd = Math.Max(Edge.Range.SegmentEnd, CanvasItem.Right); } var point1 = new Point(Edge.AxisDistance, segmentStart); var point2 = new Point(Edge.AxisDistance, segmentEnd); if (Edge.Orientation == Orientation.Horizontal) { point1 = point1.Swap(); point2 = point2.Swap(); } drawingContext.DrawLine(Pen, point1, point2); }
public virtual IDisposable Draw(DrawingContext drawingContext, Rect targetItemRect, int level) { //Default is to draw the image bits into the context: //Do not dispose of the memory stream here, because System.Media.Windows uses // retained mode rendering where the commands get batched to execute later. MemoryStream imageStream = new MemoryStream(this.ImageData); try { TransformedBitmap shrunkImage = ResizePng(imageStream, targetItemRect.Size); //DrawingContext.DrawImage will scale an image to fill the size, so modify // our target rect to be exactly the correct image position on the tile. Rect targetImageRect = new Rect(targetItemRect.X, targetItemRect.Y, shrunkImage.PixelWidth, shrunkImage.PixelHeight); drawingContext.DrawImage(shrunkImage, targetImageRect); return imageStream; //Return our stream so it can be disposed later. } catch { if (null != imageStream) { imageStream.Dispose(); } throw; } }
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) { base.OnRender(drawingContext); SolidColorBrush blackBrush = new SolidColorBrush(Color.FromRgb(0, 0, 0)); SolidColorBrush greenBrush = new SolidColorBrush(Color.FromRgb(0, 128, 0)); SolidColorBrush redBrush = new SolidColorBrush(Color.FromRgb(200, 0, 0)); Pen blackPen = new Pen(blackBrush, 1); Pen greenPen = new Pen(greenBrush, 1); Pen redPen = new Pen(redBrush, 1); drawingContext.DrawRectangle(null, blackPen, _size); if (Universe == null) { return; } foreach (FoodElement element in Universe.Food) { drawingContext.DrawEllipse(null, greenPen, new Point(element.CenterX, element.CenterY), element.Width, element.Width); } foreach (CreatureElement creature in Universe.Creatures) { drawingContext.DrawEllipse(null, redPen, new Point(creature.CenterX, creature.CenterY), creature.Width, creature.Width); } }
private void DrawBorders(System.Windows.Media.DrawingContext dc) { dc.PushClip(new RectangleGeometry(new Rect(0, 0, Width, Height))); int lineNumber = StartLine; if (lineNumber > 0) { lineNumber--; } while (lineNumber > 0 && !REPLData.KindIsGap(LineKinds[lineNumber])) { lineNumber--; } while (true) { double topY = (lineNumber - StartLine) * LineHeight + 2; lineNumber++; while (lineNumber < Lines.Count && !REPLData.KindIsGap(LineKinds[lineNumber])) { lineNumber++; } double bottomY = (lineNumber - StartLine) * LineHeight + 2; dc.DrawRoundedRectangle(InsideBrush, BorderPen, new Rect(SpaceWidth / 2, topY + topOffset, Width - SpaceWidth, bottomY - topY - LineHeight / 3), SpaceWidth, SpaceWidth); if (lineNumber >= Lines.Count - 1 || lineNumber > StartLine + Height / LineHeight) { break; } } ; dc.Pop(); }
protected override void OnRender(System.Windows.Media.DrawingContext dc) { base.OnRender(dc); if (Connections != null) { SolidColorBrush brsh = new SolidColorBrush(Colors.White); brsh.Opacity = 0.5; Pen pen = new Pen(brsh, 1.0); Point ptLast = new Point(0, 0); bool fHaveLastPoint = false; foreach (TreeConnection tcn in Connections) { fHaveLastPoint = false; foreach (DPoint dpt in tcn.LstPt) { if (!fHaveLastPoint) { ptLast = PtFromDPoint(tcn.LstPt[0]); fHaveLastPoint = true; continue; } dc.DrawLine(pen, PtFromDPoint(dpt), ptLast); ptLast = PtFromDPoint(dpt); } } } }
/// <summary> /// Participates in rendering operations. /// </summary> /// <param name="drawingContext">The drawing instructions for a specific element. This context is provided to the layout system.</param> protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) { base.OnRender(drawingContext); // Border Rect r = new Rect(0, 0, ColumnCount * CellLength, RowCount * CellLength); drawingContext.DrawRectangle(LightFill, _darkPen, r); StreamGeometry darkGeometry = new StreamGeometry(); // StreamGeometry lightGeometry = new StreamGeometry(); using (StreamGeometryContext darkContext = darkGeometry.Open()) { // using (StreamGeometryContext lightContext = lightGeometry.Open()) for (int i = 0; i < ColumnCount; i++) { for (int j = 0; j < RowCount; j++) { if (((i % 2 == 0) && (j % 2 == 0)) || ((i % 2 == 1) && (j % 2 == 1))) { CreateFigure(i * CellLength, j * CellLength, darkContext); } //else //{ // CreateFigure(i * CellLength, j * CellLength, lightContext); //} } } } darkGeometry.Freeze(); drawingContext.DrawGeometry(DarkFill, null, darkGeometry); }
protected override void OnRender(System.Windows.Media.DrawingContext dc) { base.OnRender(dc); if (Connections != null) { //连接线是否反锯齿显示(斜线需要反锯齿显示,横竖线则不需要) //RenderOptions.SetEdgeMode(this, EdgeMode.Aliased); SolidColorBrush brsh = new SolidColorBrush(Colors.Black); brsh.Opacity = 0.5; Pen pen = new Pen(brsh, 1.0); Point ptLast = new Point(0, 0); bool fHaveLastPoint = false; foreach (TreeConnection tcn in Connections) { fHaveLastPoint = false; foreach (DPoint dpt in tcn.LstPt) { if (!fHaveLastPoint) { ptLast = PtFromDPoint(tcn.LstPt[0]); fHaveLastPoint = true; continue; } dc.DrawLine(pen, PtFromDPoint(dpt), ptLast); ptLast = PtFromDPoint(dpt); } } } }
protected override void OnRender(System.Windows.Media.DrawingContext dc) { RotateTransform RT = new RotateTransform(); RT.Angle = -90; double num = this.Maximum - this.Minimum; double y = this.ReservedSpace * 0.5; FormattedText formattedText = null; double x = 0; for (double i = 0; i <= num; i += this.TickFrequency) { formattedText = new FormattedText(i.ToString(), System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 8, Brushes.Black, 1); if (this.Minimum == i) { x = 0; } else { x += this.ActualWidth / (num / this.TickFrequency); } dc.PushTransform(RT); dc.DrawText(formattedText, new Point(-20, x)); dc.Pop(); } }
public void Draw(ApplicationContext actx, SWM.DrawingContext dc, double scaleFactor, double x, double y, ImageDescription idesc) { if (drawCallback != null) { DrawingContext c = new DrawingContext(dc, scaleFactor); actx.InvokeUserCode(delegate { drawCallback(c, new Rectangle(x, y, idesc.Size.Width, idesc.Size.Height)); }); } else { if (idesc.Alpha < 1) { dc.PushOpacity(idesc.Alpha); } var f = GetBestFrame(actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false); var bmpImage = f as BitmapSource; if (bmpImage != null && (bmpImage.PixelHeight != idesc.Size.Height || bmpImage.PixelWidth != idesc.Size.Width)) { f = new TransformedBitmap(bmpImage, new ScaleTransform(idesc.Size.Width / bmpImage.PixelWidth, idesc.Size.Height / bmpImage.PixelHeight)); } dc.DrawImage(f, new Rect(x, y, idesc.Size.Width, idesc.Size.Height)); if (idesc.Alpha < 1) { dc.Pop(); } } }
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) { base.OnRender(drawingContext); var element = AdornedElement as FrameworkElement; if (element == null) { return; } var pen = new Pen(Brushes.Gray, 1); for (var x = 0; x < element.ActualWidth; x += 100) { for (var y = 0; y < element.ActualHeight; y += 100) { drawingContext.DrawLine(pen, new Point(x, 0), new Point(x, element.ActualHeight)); drawingContext.DrawLine(pen, new Point(0, y), new Point(element.ActualWidth, y)); } } }
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) { drawingContext.DrawRectangle(Brushes.Red, null, new System.Windows.Rect(0, 0, 5, 5)); drawingContext.DrawRectangle(Brushes.Red, null, new System.Windows.Rect(0, ActualHeight - 5, 5, 5)); drawingContext.DrawRectangle(Brushes.Red, null, new System.Windows.Rect(ActualWidth - 5, 0, 5, 5)); drawingContext.DrawRectangle(Brushes.Red, null, new System.Windows.Rect(ActualWidth - 5, ActualHeight - 5, 5, 5)); }
protected override void OnRender(DrawingContext drawingContext) { if (Uniter == null) return; List<Rect> rects = Uniter.Members .Select(m => new Rect(m.PointToScreen(new Point(0, 0)), m.RenderSize)) .ToList(); Point p1 = PointFromScreen(new Point(rects.Min(r => r.X), rects.Min(r => r.Y))); Point p2 = PointFromScreen(new Point(rects.Max(r => r.X + r.Width), rects.Max(r => r.Y + r.Height))); var renderRect = new Rect(p1, p2); base.OnRender(drawingContext); double verticalPixelScrollRange = renderRect.Height * Math.Abs(Uniter.VerticalScrollRange); double canvasHeight = renderRect.Height + verticalPixelScrollRange; double canvasWidth = renderRect.Width; double scale = Math.Max(canvasWidth / Source.Width, canvasHeight / Source.Height); double imageWidth = Source.Width * scale; double imageHeight = Source.Height * scale; double y = Uniter.VerticalOffset * verticalPixelScrollRange; drawingContext.DrawImage(Source, new Rect(renderRect.X, renderRect.Y - y, imageWidth, imageHeight)); }
protected override void OnRender(DrawingContext dc) { Size size = new Size(base.ActualWidth, base.ActualHeight); int tickCount = (int)((this.Maximum - this.Minimum) / this.TickFrequency) + 1; if ((this.Maximum - this.Minimum) % this.TickFrequency == 0) tickCount -= 1; Double tickFrequencySize; // Calculate tick's setting tickFrequencySize = (size.Width * this.TickFrequency / (this.Maximum - this.Minimum)); string text = ""; FormattedText formattedText = null; double num = this.Maximum - this.Minimum; int i = 0; // Draw each tick text for (i = 0; i <= tickCount; i++) { text = Convert.ToString(Convert.ToInt32(this.Minimum + this.TickFrequency * i), 10); //g.DrawString(text, font, brush, drawRect.Left + tickFrequencySize * i, drawRect.Top + drawRect.Height/2, stringFormat); formattedText = new FormattedText(text, CultureInfo.GetCultureInfo("ru-Ru"), FlowDirection.LeftToRight, new Typeface("Arial"), 8, Brushes.Black); dc.DrawText(formattedText, new Point((tickFrequencySize * i), 30)); } }
protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); if (AdornedElement.RenderSize.Width < 20) return; TranslateTransform transform = new TranslateTransform ( AdornedElement.RenderSize.Width - 15, (AdornedElement.RenderSize.Height - 5) / 2 ); transform = new TranslateTransform ( AdornedElement.RenderSize.Width / 2 - 3.5, AdornedElement.RenderSize.Height / 2 - 10 ); drawingContext.PushTransform(transform); Geometry geometry = ascGeometry; if (this.Direction == ListSortDirection.Descending) geometry = descGeometry; drawingContext.DrawGeometry(Brushes.LightGray, null, geometry); drawingContext.Pop(); }
internal DrawingContext(System.Windows.Media.DrawingContext dc, double scaleFactor) { Context = dc; ScaleFactor = scaleFactor; AllocatePen(Color.FromRgb(0, 0, 0), 1, DashStyles.Solid); ResetPath(); }
//private void DrawBitblt(DrawingContext dc) //{ // //增加剪裁后九宫 // if (DrawImageWith9Cells == false) // { // ImageSource source = GetImageSource(); // Rect rect = new Rect(new Point(0, 0), new Size(ActualWidth, ActualHeight)); // dc.DrawImage(Source, rect); // } // else // { // RenderWith9Cells(dc); // } //} private void RenderWith9Cells(System.Windows.Media.DrawingContext dc) { if (Source == null) { return; } //if (ClipPadding.Right == 0 || ClipPadding.Bottom == 0) return; ImageSource source = Source; Uri u = new Uri(source.ToString()); var image = new BitmapImage(u); if (ClipRect != Int32Rect.Empty) { //预剪裁 image = SplitImage(image, ClipRect) as BitmapImage; } double contentWidth = image.PixelWidth - ClipPadding.Left - ClipPadding.Right; double contentHeight = image.PixelHeight - ClipPadding.Top - ClipPadding.Bottom; Int32Rect contentRect = new Int32Rect((int)ClipPadding.Left, (int)ClipPadding.Top, (int)contentWidth, (int)contentHeight); // Rect r = new Rect(new Point(),RenderSize); // dc.DrawImage(image,r); //return; // image.BeginInit(); // image.EndInit(); ImageSource[] images = Get9CellImageSource(image, contentRect); if (images == null || images.Length != 9) { base.OnRender(dc); return; } DrawFrame(dc, images, contentRect); // DrawContent(contentRect, dc); }
/// <summary> /// Draws the curved connector. /// </summary> /// <param name="drawingContext">The drawing context.</param> private void DrawCurvedConnector(DrawingContext drawingContext) { Point start = this.StartNode.Center; Point end = this.EndNode.Center; double offsetX = (double)(DiagramContext.DetermineNestedOffset(this.StartNode.Node.MessageInfo) * 15.0D); start.Offset(offsetX, 0); end.Offset(offsetX, 0); start.Offset(0, -12); Point cornerOne = new Point(start.X + 15, start.Y); double nestedCallLength = (double)(DiagramContext.NestedCallCount(this.StartNode.Node.MessageInfo) * 40.0D); Point intermediateOne = new Point(cornerOne.X, cornerOne.Y + 24); Point intermediateTwo = new Point(cornerOne.X, cornerOne.Y + nestedCallLength); Point cornerTwo = new Point(intermediateTwo.X, intermediateTwo.Y + 24); end.Offset(0, 12 + nestedCallLength); drawingContext.DrawLine(this.Pen, start, cornerOne); drawingContext.DrawLine(this.Pen, cornerOne, intermediateOne); drawingContext.DrawLine(this.DashedPen, intermediateOne, intermediateTwo); drawingContext.DrawLine(this.Pen, intermediateTwo, cornerTwo); drawingContext.DrawLine(this.Pen, cornerTwo, end); string path = string.Format(CultureInfo.InvariantCulture, "M{0}L{1},{2}L{1},{3}Z", end, end.X + 3.464, end.Y - 2, end.Y + 2); drawingContext.DrawGeometry(this.Pen.Brush, this.Pen, Geometry.Parse(path)); Point textStart = new Point(cornerOne.X + 4, cornerOne.Y + 5); Brush brush = Brushes.Black; drawingContext.DrawText(new FormattedText(this.StartNode.Node.MessageInfo.ToString(), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, new Typeface("Segoe UI"), 9, brush), textStart); }
protected override void OnRender(System.Windows.Media.DrawingContext dc) { base.OnRender(dc); try { int cx = (int)Width / brushSizeX; int cy = (int)Height / brushSizeY; // draw vertical lines: for (int i = 0; i <= cx; i++) { dc.DrawLine(penGrid, new Point(i * brushSizeX, 0), new Point(i * brushSizeX, Height)); } // draw horizontal lines: for (int i = 0; i <= cy; i++) { dc.DrawLine(penGrid, new Point(0, i * brushSizeY), new Point(Width, i * brushSizeY)); } // draw selection: if (selection.Width > 0 && selection.Height > 0) { dc.DrawRectangle(Brushes.Transparent, penBlack, selection); dc.DrawRectangle(Brushes.Transparent, penWhite, selection); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
protected override void OnRender(System.Windows.Media.DrawingContext dc) { base.OnRender(dc); foreach (var placement in Screen.Entities) { var entity = Screen.Stage.Project.EntityByName(placement.entity); if (entity != null) { var sprite = entity.DefaultSprite; if (sprite != null) { var frame = SpriteBitmapCache.GetOrLoadFrame(sprite.SheetPath.Absolute, sprite.CurrentFrame.SheetLocation); var flip = (placement.direction == Common.Direction.Left) ^ sprite.Reversed; int hx = flip ? sprite.Width - sprite.HotSpot.X : sprite.HotSpot.X; dc.DrawImage(frame, new Rect(this.Zoom * (placement.screenX - hx), this.Zoom * (placement.screenY - sprite.HotSpot.Y), this.Zoom * frame.PixelWidth, this.Zoom * frame.PixelHeight)); continue; } } dc.DrawEllipse(Brushes.Orange, null, new System.Windows.Point(this.Zoom * placement.screenX, this.Zoom * placement.screenY), 10 * Zoom, 10 * Zoom); } }
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) { double fontSize; Typeface typeFace; TextAlignment alignment; FlowDirection flowDirection; double padding; if (AdornedPasswordBox != null) { alignment = ConvertAlignment(AdornedPasswordBox.HorizontalContentAlignment); flowDirection = AdornedPasswordBox.FlowDirection; fontSize = AdornedPasswordBox.FontSize; typeFace = AdornedPasswordBox.FontFamily.GetTypefaces().FirstOrDefault(); padding = 6; } else { alignment = AdornedTextBox.ReadLocalValue(TextBox.TextAlignmentProperty) != DependencyProperty.UnsetValue ? AdornedTextBox.TextAlignment : ConvertAlignment(AdornedTextBox.HorizontalContentAlignment); flowDirection = AdornedTextBox.FlowDirection; fontSize = AdornedTextBox.FontSize; typeFace = AdornedTextBox.FontFamily.GetTypefaces().FirstOrDefault(); padding = 6; } var text = new System.Windows.Media.FormattedText(PlaceholderText ?? "", CultureInfo.CurrentCulture, flowDirection, typeFace, fontSize, System.Windows.Media.Brushes.LightGray) { TextAlignment = alignment }; drawingContext.DrawText(text, new System.Windows.Point(padding, (RenderSize.Height - text.Height) / 2)); }
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) { //if (!(_target is IScreen)) { if (_isOpening) { SolidColorBrush fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#2200FF00")); drawingContext.DrawRectangle(fill, null, new Rect(0, 0, ActualWidth, ActualHeight)); } else { SolidColorBrush fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#050000FF")); drawingContext.DrawRectangle(fill, null, new Rect(0, 0, ActualWidth, ActualHeight)); } if (_canDrop) { SolidColorBrush border = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#CCFFFFFF")); SolidColorBrush dot = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#CC0000FF")); RenderOptions.SetEdgeMode(this, EdgeMode.Unspecified); drawingContext.DrawEllipse(border, null, new Point(0, 0), RADIUS + BORDER, RADIUS + BORDER); drawingContext.DrawEllipse(border, null, new Point(0, ActualHeight), RADIUS + BORDER, RADIUS + BORDER); drawingContext.DrawEllipse(border, null, new Point(ActualWidth, 0), RADIUS + BORDER, RADIUS + BORDER); drawingContext.DrawEllipse(border, null, new Point(ActualWidth, ActualHeight), RADIUS + BORDER, RADIUS + BORDER); drawingContext.DrawEllipse(dot, null, new Point(0, 0), RADIUS, RADIUS); drawingContext.DrawEllipse(dot, null, new Point(0, ActualHeight), RADIUS, RADIUS); drawingContext.DrawEllipse(dot, null, new Point(ActualWidth, 0), RADIUS, RADIUS); drawingContext.DrawEllipse(dot, null, new Point(ActualWidth, ActualHeight), RADIUS, RADIUS); } } }
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) { Pen pen = new Pen(new SolidColorBrush(Colors.Black), 1); if (LightOn) { GradientStopCollection stopC2 = new GradientStopCollection(); stopC2.Add(new GradientStop(Colors.White, 0)); stopC2.Add(new GradientStop(Colors.Red, 1)); RadialGradientBrush r2 = new RadialGradientBrush(stopC2); r2.RadiusX = 1; r2.RadiusY = 1; r2.GradientOrigin = new Point(0.7, 0.3); drawingContext.DrawEllipse(r2, pen, new Point(Width / 2, Height / 2), Width / 2, Height / 2); } else { GradientStopCollection stopC1 = new GradientStopCollection(); stopC1.Add(new GradientStop(Colors.White, 0)); stopC1.Add(new GradientStop(Colors.LightGreen, 1)); RadialGradientBrush r1 = new RadialGradientBrush(stopC1); r1.RadiusX = 1; r1.RadiusY = 1; r1.GradientOrigin = new Point(0.7, 0.3); drawingContext.DrawEllipse(r1, pen, new Point(Width / 2, Height / 2), Width / 2, Height / 2); } }
/// <summary> /// Draw the legend item /// </summary> /// <param name="dc">DrawingContext on which to draw</param> /// <param name="position">The position on the drawing context to draw relative to.</param> public override void Draw(System.Windows.Media.DrawingContext dc, System.Windows.Point position) { Pen linePen = new Pen(Brushes.Black, 1.0); dc.DrawRectangle(_fill, linePen, new Rect((int)position.X + 2, (int)position.Y + 2, 28, (int)Dimensions.Height - 4)); dc.DrawText(_formattedText, new Point(38 + position.X, 2 + position.Y)); }
/// <summary> /// Creates a new System.Windows.Media.ImageSource of a specified FontAwesomeIcon and foreground System.Windows.Media.Brush. /// </summary> /// <param name="icon">The FontAwesome icon to be drawn.</param> /// <param name="foregroundBrush">The System.Windows.Media.Brush to be used as the foreground.</param> /// <returns>A new System.Windows.Media.ImageSource</returns> public static System.Windows.Media.ImageSource GetImageSource(int icon, System.Windows.Media.Brush foregroundBrush, double emSize = 100, double margin = 0) { string charIcon = char.ConvertFromUtf32(icon); if (_Typeface == null) { _Typeface = new System.Windows.Media.Typeface(FontFamily, System.Windows.FontStyles.Normal, System.Windows.FontWeights.Normal, System.Windows.FontStretches.Normal); } ; System.Windows.Media.DrawingVisual visual = new System.Windows.Media.DrawingVisual(); using (System.Windows.Media.DrawingContext drawingContext = visual.RenderOpen()) { FormattedText ft = new System.Windows.Media.FormattedText( charIcon, System.Globalization.CultureInfo.InvariantCulture, System.Windows.FlowDirection.LeftToRight, _Typeface, emSize - (2 * margin), foregroundBrush); ft.TextAlignment = System.Windows.TextAlignment.Center; drawingContext.DrawRectangle(null, new Pen(Brushes.Black, 0), new System.Windows.Rect(0, 0, emSize, emSize)); drawingContext.DrawText(ft, new System.Windows.Point(emSize / 2, margin)); }; return(new System.Windows.Media.DrawingImage(visual.Drawing)); }
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) { if (!MbRect.IsEmpty) { drawingContext.DrawRectangle(m_Brush, m_Pen, m_MbRect); } }
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) { SolidColorBrush renderBrush = new SolidColorBrush(Colors.LightCoral); Pen renderPen = new Pen(new SolidColorBrush(Colors.DarkBlue), 1.0); if (this.AdornedElement is Path path) { double fraction = 0.5; //the relative point of the curve Point pt; //the absolute point of the curve Point tg; //the tangent point of the curve (path.RenderedGeometry as PathGeometry).GetPointAtFractionLength( fraction, out pt, out tg); drawingContext.DrawEllipse(renderBrush, renderPen, new Point(pt.X, pt.Y), 20, 20); } if (this.AdornedElement is PathPolyLine pathpolyline) { var y = ((ConnectionPoint)pathpolyline.EndPoint).Position.Y + ((ConnectionPoint)pathpolyline.StartPoint).Position.Y; var x = ((ConnectionPoint)pathpolyline.EndPoint).Position.X + ((ConnectionPoint)pathpolyline.StartPoint).Position.X; drawingContext.DrawEllipse(renderBrush, renderPen, new Point(x / 2, y / 2), 20, 20); } else { drawingContext.DrawEllipse(renderBrush, renderPen, new Point(10, 10), 20, 20); } }
protected override void OnRender(DrawingContext dc) { var indent = NodeView.CalculateIndent(NodeView.Node); var p = new Point(indent + 4.5, 0); if (!NodeView.Node.IsRoot || NodeView.ParentTreeView.ShowRootExpander) { dc.DrawLine(pen, new Point(p.X, ActualHeight / 2), new Point(p.X + 10, ActualHeight / 2)); } if (NodeView.Node.IsRoot) return; if (NodeView.Node.IsLast) { dc.DrawLine(pen, p, new Point(p.X, ActualHeight / 2)); } else { dc.DrawLine(pen, p, new Point(p.X, ActualHeight)); } var current = NodeView.Node; while (true) { p.X -= 19; current = current.Parent; if (p.X < 0) break; if (!current.IsLast) { dc.DrawLine(pen, p, new Point(p.X, ActualHeight)); } } }
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) { base.OnRender(drawingContext); FormattedText formattedText = formattedText = new FormattedText( Text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), ActualHeight, Brushes.Black); formattedText.TextAlignment = TextAlignment.Left; formattedText.MaxTextWidth = ActualWidth - Padding.Left - Padding.Right; formattedText.Trimming = TextTrimming.None; double step = ActualHeight / 20; double fontSize = 0; for (double i = ActualHeight - step; i >= step; i -= step) { if (formattedText.Height <= ActualHeight - Padding.Top - Padding.Bottom) { break; } formattedText.SetFontSize(i); fontSize = i; } if (fontSize > 14) { formattedText.SetFontSize(14); } formattedText.MaxTextHeight = ActualHeight; drawingContext.DrawText(formattedText, new Point(Padding.Left, Padding.Top)); }
public bool DrawString( System.Windows.Media.DrawingContext graphics, System.Windows.Media.FontFamily fontFamily, System.Windows.FontStyle fontStyle, System.Windows.FontWeight fontWeight, double fontSize, string strText, System.Windows.Point ptDraw, System.Globalization.CultureInfo ci) { Geometry path = GDIPath.CreateTextGeometry(strText, fontFamily, fontStyle, fontWeight, fontSize, ptDraw, ci); for (int i = 1; i <= m_nThickness; ++i) { SolidColorBrush solidbrush = new SolidColorBrush(m_clrOutline); Pen pen = new Pen(solidbrush, i); pen.LineJoin = PenLineJoin.Round; if (m_bClrText) { SolidColorBrush brush = new SolidColorBrush(m_clrText); graphics.DrawGeometry(brush, pen, path); } else { graphics.DrawGeometry(m_brushText, pen, path); } } return(true); }
/// <summary> /// Handle repaint event to draw component. /// </summary> /// <param name="dc">Platform independence drawing context.</param> protected override void OnRender(System.Windows.Media.DrawingContext dc) { #if DEBUG Stopwatch watch = Stopwatch.StartNew(); #endif if (this.currentWorksheet != null && this.currentWorksheet.workbook != null && this.currentWorksheet.controlAdapter != null) { dc.DrawRectangle(Brushes.White, null, new Rect(0, 0, this.RenderSize.Width, this.RenderSize.Height)); this.renderer.Reset(); ((WPFRenderer)this.renderer).SetPlatformGraphics(dc); var rgdc = new CellDrawingContext(this.currentWorksheet, DrawMode.View, this.renderer); this.currentWorksheet.ViewportController.Draw(rgdc); } #if DEBUG watch.Stop(); long ms = watch.ElapsedMilliseconds; if (ms > 30) { Debug.WriteLine(string.Format("end draw: {0} ms.", watch.ElapsedMilliseconds)); } #endif }
public void Draw(TextView textView, System.Windows.Media.DrawingContext drawingContext) { ISegment s = element.Segment; if (s != null) { BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder(); geoBuilder.AlignToMiddleOfPixels = true; if (Layer == KnownLayer.Background) { geoBuilder.AddSegment(textView, s); drawingContext.DrawGeometry(backgroundBrush, null, geoBuilder.CreateGeometry()); } else { // draw foreground only if active if (element.isCaretInside) { geoBuilder.AddSegment(textView, s); foreach (BoundActiveElement boundElement in element.context.ActiveElements.OfType <BoundActiveElement>()) { if (boundElement.targetElement == element) { geoBuilder.AddSegment(textView, boundElement.Segment); geoBuilder.CloseFigure(); } } drawingContext.DrawGeometry(null, activeBorderPen, geoBuilder.CreateGeometry()); } } } }
protected override void OnRender(System.Windows.Media.DrawingContext dc) { foreach (Line line in graphics_) { if (HasNonComTrain.Count != 0) { dc.DrawLine(NonComTrainOccupy_, line.Points[0], line.Points[1]); } else { System.Windows.Point Middle = new System.Windows.Point((line.Points[0].X + line.Points[1].X) / 2, (line.Points[0].Y + line.Points[1].Y) / 2); if (AxleOccupy == 0) { dc.DrawLine(AxleOccupyPen_, line.Points[0], line.Points[1]); } else { dc.DrawLine(DefaultPen_, line.Points[0], line.Points[1]); } if (IsFrontLogicOccupy && IsLastLogicOccupy) { dc.DrawLine(TrainOccpyPen_, line.Points[0], line.Points[1]); } else if (IsFrontLogicOccupy && !IsLastLogicOccupy) { dc.DrawLine(TrainOccpyPen_, line.Points[0], Middle); } else if (!IsFrontLogicOccupy && IsLastLogicOccupy) { dc.DrawLine(TrainOccpyPen_, Middle, line.Points[1]); } } } dc.DrawText(formattedName_, namePoint_); }
protected override void OnRender(System.Windows.Media.DrawingContext dc) { if (Double.IsNaN(Width) || Double.IsNaN(Height)) { return; } BackBrush = new SolidColorBrush(Colors.AntiqueWhite); BackCursorBrush = new SolidColorBrush(Colors.Yellow); ForeBrush = new SolidColorBrush(Colors.Black); BorderBrush = new SolidColorBrush(Colors.Chocolate); BackHighBrush = new SolidColorBrush(Colors.Red); ForeHighBrush = new SolidColorBrush(Colors.Yellow); BorderPen = new Pen(BorderBrush, 1); InsideBrush = new SolidColorBrush(Colors.Beige); SelectedForeBrush = new SolidColorBrush(Colors.White); SelectedBackBrush = new SolidColorBrush(Colors.DarkBlue); NonErrorReplyBrush = new SolidColorBrush(Colors.Chocolate); ErrorReplyBrush = new SolidColorBrush(Colors.Red); bottomOffset = LineHeight / 3; topOffset = 2 * LineHeight / 3; dc.DrawRectangle(BackBrush, null, new Rect(0, 0, Width, Height)); DrawBorders(dc); DrawText(dc); }
protected override void DrawText(int index, System.Windows.Media.DrawingContext drawingContext, ref Brush brush) { if (this.ActualWidth - SCROLLBARWIDTH < 0) { return; } FormattedText text = FormatText(getText(index), brush); int fromborder = 0; if (pItem[Findlist[index]].Playing) { text.SetFontWeight(FontWeights.Bold); } if (string.IsNullOrEmpty(pItem[Findlist[index]].Duration)) { drawingContext.DrawText(text, new Point(3, (index - LowIndex) * ISize + 3)); } else { fromborder = 6 + pItem[Findlist[index]].Duration.Length * 5; text.MaxTextWidth -= fromborder; drawingContext.DrawText(text, new Point(3, (index - LowIndex) * ISize + 3)); text = FormatText(pItem[Findlist[index]].Duration, brush); if ((item != null) && HighIndex - LowIndex < GetCount() - 1) { fromborder += SCROLLBARWIDTH; } drawingContext.DrawText(text, new Point(this.ActualWidth - fromborder, (index - LowIndex) * ISize + 3)); } }
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) { TranslateTransform translation = this.RenderTransform as TranslateTransform; if (translation == null) { translation = new TranslateTransform(); this.RenderTransform = translation; } double width = this.Width; double height = this.Height; if (double.IsNaN(width)) { width = this.ActualWidth; } if (double.IsNaN(height)) { height = this.ActualHeight; } translation.X = -width * 0.5; translation.Y = -height * 0.5; base.OnRender(drawingContext); }
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) { Typeface Typeface1 = new Typeface(new FontFamily("Century"), FontStyles.Normal, FontWeights.Bold, FontStretches.Normal); FormattedText ft = new FormattedText(TextUnderImage, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, Typeface1, 18, Brushes.Red, 1.0); drawingContext.DrawText(ft, new Point(0, 0)); }
protected override void DrawVisualThumbnail(DrawingContext drawingContext, out string title, ref BitmapSource icon) { var aeroColor = (Color) Application.Current.Resources["AeroColor"]; var aeroBrush = new SolidColorBrush(aeroColor); var aeroPen = new Pen(aeroBrush, 7); var largeIcon = (BitmapSource) Application.Current.Resources["TextClipboardItemIcon"]; var fontFamily = (FontFamily) Application.Current.Resources["CuprumFont"]; var typeface = new Typeface(fontFamily, FontStyles.Normal, FontWeights.Light, FontStretches.Normal); const int textOffset = VisualThumbnailMargin + 51 + VisualThumbnailMargin / 2; var text = new FormattedText(Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, 15, aeroBrush); text.TextAlignment = TextAlignment.Left; text.MaxTextWidth = VisualThumbnailWidth - textOffset - VisualThumbnailMargin; text.MaxTextHeight = VisualThumbnailHeight - VisualThumbnailMargin * 2; drawingContext.DrawRectangle(Brushes.White, aeroPen, new Rect(-1, -1, VisualThumbnailWidth + 2, VisualThumbnailHeight + 2)); drawingContext.DrawImage(largeIcon, new Rect(VisualThumbnailMargin, VisualThumbnailMargin, 51, 66)); drawingContext.DrawText(text, new Point(textOffset, VisualThumbnailMargin)); title = Text; }
//用这个方法设定高度违背了设计原则,但实在找不到更合适的高度设置方式 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) { base.OnRender(drawingContext); double height = Application.Current.MainWindow.ActualHeight; this.tableDataGrid.Height = height - 200; }