The reason behind slow performance in WPF

前端 未结 3 1663
离开以前
离开以前 2020-12-14 04:42

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 <

3条回答
  •  一整个雨季
    2020-12-14 05:06

    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.

提交回复
热议问题