How do you apply a Scale Translation to a DrawingContext?

大兔子大兔子 提交于 2019-12-11 02:15:01

问题


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:


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.



来源:https://stackoverflow.com/questions/1099945/how-do-you-apply-a-scale-translation-to-a-drawingcontext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!