DrawingContext + Transform issue

A

Anthony Paul

Hello everyone,

I have an issue where I'm creating a visuals container to host some
lightweight visuals, but when I apply transforms to the individual
visuals they go buggers.

First, I downloaded the MS sample code located at the bottom of the
following page :

http://msdn.microsoft.com/en-us/library/system.windows.media.visualcollection.aspx

I modify the "CreateDrawingVisualText" and add the following line
right after the call to RenderOpen :

drawingContext.PushTransform(new ScaleTransform(-1, 1, 0.5, 0.5)); //
inverts horizontally

and finally add the following line right before the call to Close :

drawingContext.Pop();

The method should now look as follows :

private DrawingVisual CreateDrawingVisualText()
{
// Create an instance of a DrawingVisual.
DrawingVisual drawingVisual = new DrawingVisual();

// Retrieve the DrawingContext from the DrawingVisual.
DrawingContext drawingContext =
drawingVisual.RenderOpen();
drawingContext.PushTransform(new ScaleTransform(-1, 1,
0.5, 0.5));

// Draw a formatted text string into the DrawingContext.
drawingContext.DrawText(
new FormattedText("Click Me!",
CultureInfo.GetCultureInfo("en-us"),
FlowDirection.LeftToRight,
new Typeface("Verdana"),
36, System.Windows.Media.Brushes.Black),
new System.Windows.Point(200, 116));

// Close the DrawingContext to persist changes to the
DrawingVisual.
drawingContext.Pop();
drawingContext.Close();

return drawingVisual;
}

note : feel free to try any type of transform; they simply won't work!

Any thoughts?

Regards,

Anthony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top