Text update slowing down app

流过昼夜 提交于 2019-12-23 01:58:45

问题


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.


回答1:


TextBlocks were not noticeably faster than Labels, but Glyphs gave my calendar whiplash.

Replacing this

<TextBlock Padding="5"
           FontFamily="Narkisim"
           FontWeight="Bold"
           FontSize="20"
           Text="{Binding HebrewDate}"/>

with this

<Glyphs Name="HebrewDate"
        Margin="5"
        StyleSimulations="BoldSimulation"
        FontUri = "/Fonts/nrkis.ttf"
        FontRenderingEmSize = "20"
        UnicodeString = "5771 ןושח ה"
        Fill = "Black"/>

made scrolling super fast.

Some notes:

  1. Glyphs do not support binding, so I had to give each one a name and update them in the code behind, like so:

    HebrewDate.UnicodeString = zman.HebrewDate;
    
  2. 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 retained Labels for those strings which use vowels.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/6910689/text-update-slowing-down-app

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