Search code examples
c#wpfoptimizationglyph

Text update slowing down app


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.


Solution

  • 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.