Tag Archives: OnRender

Get font metrics in a WPF program using C#

This example explains how to get font metrics in a WPF application. It’s actually not too hard, it’s just hard to figure out how to do it. The font metrics are tucked away inside the FormattedText object and the Typeface … Continue reading

Posted in drawing, geometry, graphics, wpf, XAML | Tagged , , , , , , , , , , , , , , , , , , , , , | Leave a comment

Easily render rotated text in a WPF program using C#

The example Render text easily in a WPF program using C# shows how to make an extension method that makes rendering text easy in WPF. This example makes a similar extension method that helps you render rotated text. This is … Continue reading

Posted in drawing, extension methods, geometry, graphics, wpf, XAML | Tagged , , , , , , , , , , , , , , , , , , , | 1 Comment

Render text filled with an image in a WPF program using C#

The example Render outlined text in a WPF program using C# shows how to draw text that is filled with one color and outlined with another. This example uses the following overridden OnRender to render text filled with an image. … Continue reading

Posted in drawing, geometry, graphics, wpf, XAML | Tagged , , , , , , , , , , , , , , , , , , , | Leave a comment

Render outlined text in a WPF program using C#

The example Render text in a WPF program using C# shows how to draw basic text. This example uses the following overridden OnRender to draw outlined text. protected override void OnRender(DrawingContext drawingContext) { // Clear the background. Rect bg_rect = … Continue reading

Posted in drawing, geometry, graphics, wpf, XAML | Tagged , , , , , , , , , , , , , , , , , , | 2 Comments

Render text easily in a WPF program using C#

The example Render text in a WPF program using C# explains how to draw text in WPF code. This example uses the following extension method to make drawing text easier. // Draw text at the indicated location. public static void … Continue reading

Posted in drawing, extension methods, geometry, graphics, wpf, XAML | Tagged , , , , , , , , , , , , , , , , , | 2 Comments

Render text in a WPF program using C#

Normally to display text in WPF you use some sort of object such as a Label or TextBlock, but you can draw text yourself if necessary. To make this easier, at design time I set the window’s Background property to … Continue reading

Posted in drawing, geometry, graphics, wpf, XAML | Tagged , , , , , , , , , , , , , , , , , , | 3 Comments

Render polygons and polylines in a WPF program using C#

WPF lets you do all sorts of interesting things that are much harder in Windows Forms applications. However sometimes, as in this example, it makes simple things much harder. (WPF’s slogan should be, “Twice as flexible and only five times … Continue reading

Posted in drawing, extension methods, geometry, graphics, wpf, XAML | Tagged , , , , , , , , , , , , , , , , , , , , , , , | 2 Comments

Render dashed lines in a WPF program using C#

When you draw in WPF, you create a Pen object. You can set that object’s DashStyle to make the pen draw dashed or dotted lines. The following code shows how this example draws the second line from the top. Pen … Continue reading

Posted in drawing, geometry, graphics, wpf, XAML | Tagged , , , , , , , , , , , , , , , , , , , , | Leave a comment

Render an ellipse in a WPF program using C#

This example shows how you can render an ellipse in a WPF program. Normally to draw shapes in WPF you use some sort of object. You can add Ellipse, Line, Path, Polygon, Polyline, and Rectangle objects to a window and … Continue reading

Posted in drawing, geometry, graphics, wpf, XAML | Tagged , , , , , , , , , , , , , | 2 Comments