I\'m creating a large number of texts in WPF using DrawText
and then adding them to a single Canvas
.
I need to redraw the screen in each <
The likely culprit is the fact that you are clearing out and rebuilding your visual tree on each wheel event. According to your own post, that tree includes a "large number" of text elements. For each event that comes in, each of those text elements must be recreated, reformatted, measured, and eventually rendered. That is not the way to accomplish simple text scaling.
Rather than setting a ScaleTransform
on each FormattedText
element, set one on the element containing the text. Depending on your needs, you can set a RenderTransform
or LayoutTransform
. Then, when you receive wheel events, adjust the Scale
property accordingly. Don't rebuild the text on each event.
I would also do what other have recommended and bind an ItemsControl
to the list of columns and generate the text that way. There is no reason you should need to do this by hand.