How do you apply a Scale Translation to a DrawingC

2019-07-14 08:42发布

I have a Canvas with a scale translation applied in XAML. Using DrawingContext I draw lines on the Canvas. I now need to add text to the screen. I thought with formatted text I could apply a translation, but neither Formatted Text or DrawingContext accepts RenderTransform. How do I apply a scale translation to the text so it will counter the scale translation of the canvas?

 ftext = New FormattedText("N", CultureInfo.GetCultureInfo("en-us"), Windows.FlowDirection.LeftToRight, face, Me.DBFontSize, FalconDataBlock.Foreground)
 context.DrawText(ftext, .TargetLineInfo.EndAsWinPoint)

1条回答
三岁会撩人
2楼-- · 2019-07-14 09:08

In most UI apps, instead of using a DrawingContext, the right thing to do might be to add a child TextBlock to the Canvas, and change the TextBlock's RenderTransform.

However, assuming you have a good reason for using a DrawingContext, you could use DrawingContext.PushTransform to push the transform you need (scale, translation, etc.), just before you invoke DrawText. Use DrawingContext.Pop to restore the prior state after you're done with DrawText.

查看更多
登录 后发表回答