文本更新减慢应用程序速度
我有一个希伯来日历应用程序,其中每一天都是一个用户控件。我在该控件中有 6 个标签,分别表示英语日期、希伯来语日期、犹太节日和其他一些用户定义的数据。滚动时,标签的内容会随着 UserControl 的日期值一周的上升或下降而变化。滚动速度明显慢于 Microsoft Outlook 日历,分析显示花费时间最长的部分是更新标签内容,而我的代码并未处理该部分。
有什么办法可以让这件事进展得更快吗? MS Outlook 似乎有相当数量的文本字段,并且滚动很流畅。
I have a Hebrew calendar app where each day is a UserControl. I have 6 labels in that control for the English date, the Hebrew date, Jewish holidays and some other user-defined data. When scrolling, the labels' content changes as the date value for the UserControl goes up or down a week. The scrolling is noticeably slower than Microsoft Outlook Calendar, and profiling reveals that the part taking the longest is updating the label contents, which is not handled by my code.
Is there some way I can make this go faster? MS Outlook seems to have a comparable number of text fields, and the scrolling is smooth.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
TextBlocks
并不比Labels
快得多,但Glyphs
却给我的日历带来了困扰。这个替换
用
它使得滚动速度变得非常快。
一些注意事项:
Glyphs
不支持绑定,因此我必须给每个字形一个名称并在后面的代码中更新它们,如下所示:Glyphs
code> 没有布局功能,因此希伯来语文本向后显示。我必须使用 倒车功能。即使在反转之后,希伯来语元音点也未对齐,因此我为那些使用元音的字符串保留了Labels
。TextBlocks
were not noticeably faster thanLabels
, butGlyphs
gave my calendar whiplash.Replacing this
with this
made scrolling super fast.
Some notes:
Glyphs
do not support binding, so I had to give each one a name and update them in the code behind, like so:Glyphs
don't have Layout functionality so Hebrew text was coming out backwards. I had to preprocess the Hebrew strings with a reversing function. Even after reversing, the Hebrew vowel points came out misaligned, so I retainedLabels
for those strings which use vowels.我不能确定,但 MS Outlook 的编码方式可能比 WPF 更快,也许使用 DirectX 来快速显示图形。
否则,我可能建议减少一次更新的绑定数量,我建议使用额外的线程在有空闲周期时逐渐更新标签,而不是一次全部更新,这可能会导致你的口吃。
I can't be sure but it is possible that MS Outlook was coded in something faster than WPF, perhaps using DirectX to show the graphics rapidly.
Otherwise I might suggest toning down on the number of bindings updating at once, I would suggest using an additional thread to gradually update the labels as and when there are spare cycles instead of all at once, which might be causing your stuttering.
为了配合之前的答案,我推荐后台工作者。利用后台工作人员来执行滚动期间执行的最耗时的操作。
http://msdn.microsoft.com/en-us/library /system.componentmodel.backgroundworker.aspx
To go along with the previous answer, I recommend the background worker. Utilize the background worker for your most time consuming operation that gets executed during the scroll.
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx