在画布上动态添加文本的最快方法 [英] Fastest way to add text on canvas dynamically
问题描述
我制作了一个简单的图表,将堆叠面板放在画布上,然后根据给出的数据用标签填充堆叠面板,但是我对性能并不满意.
如果我用列表框更改堆栈面板,而不是用标签添加字符串,则渲染数据会更快吗?我需要显示的数据是来自大量字符串列表的子集.移动索引时,我必须清除所有列表框并用新数据填充它们.
还是有更快的方法呢?
我所有的字符串都是4个字符.是否可以将方向更改为垂直方向,以便每个列表框显示类似这样的内容
A
A
A
A
B
B
B
B
C
C
C
C
D
D
D
D
等...
字符串为AAAA,BBBB,CCCC,DDDD.
I made a simple chart by putting stack panels on a canvas and then filling the stack panels with lables according to the data given.However I am not very happy with the performance.
If I change the stack panels with listboxes, and instead of lables add strings, would it be faster to render the data? The data I need to show is a subset from a large array of lists of strings. When I move the index, I have to clear all the listboxes and fill them with the new data.
Or is there a faster way to do it?
All my strings are of 4 characters. Is it possible to change the orientation to vertical so that each listbox shows something like this
A
A
A
A
B
B
B
B
C
C
C
C
D
D
D
D
etc...
The strings are AAAA, BBBB, CCCC, DDDD.
推荐答案
对于垂直文本,可以使用本文中提供的VerticalTextBlock
实现: http://blogs.msdn.com/b/delay/archive/2008/06/19/text-from-a-slightly-different-perspective-verticaltextblock-control-sample-for-silverlight-2.aspx [
For a vertical text, you can use implementation ofVerticalTextBlock
offered in this post: http://blogs.msdn.com/b/delay/archive/2008/06/19/text-from-a-slightly-different-perspective-verticaltextblock-control-sample-for-silverlight-2.aspx[^].
Now, dynamic adding the the canvas:
TextBlock tb = new VerticalTextBlock();
tb.Text = "some text";
//... whatever properties your need
myCanvas.Children.Add(tb);
为什么将堆栈面板放在画布上?您正在为画布设置动画吗?如果没有,那似乎是多余的.
Why are you putting stackpanels on a canvas? Are you animating the canvas? If not, it just seems redundant.
这篇关于在画布上动态添加文本的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!