locked
Colorize one or several part(s) of a label's text RRS feed

  • Question

  • User319859 posted

    Hi,

    I developed a page presenting some users. This last one is simply containing an entry and a listing.

    I tried to colorize the users' informations matching with the text previously typed into the entry by using the Label property named FormattedText.

    At first, the result was not so great and I discovered that using the FormattedText is actually displaying the informations in a very slowy way so I implemented a little hack that was simply splitting my string in X substrings and creating a label for each one of them that I would concat into an horizontal stacklayout.

    The solution is working great on iOS, but on Android it's lagging a lot when I am scrolling down / up...

    I am surprise to see that there is not control handling such basic behavior or maybe I missed them. Does anyone have an idea to implement a better solution ?

    I thank you in advance and wish you a great weekend ! Best regards,

    Friday, January 4, 2019 3:02 PM

Answers

  • User180523 posted

    I'd be interested to really test the lag. I've never seen a performance problem with it. But I'm not putting more than 20 or so uses of it on a page. Are you doing EXTENSIVE number of these? Or could the delay really be coming from binding or fetching data?

    I guess my first performance test would be to create a number of such formatted labeles using static, hard-coded text - just as a test - to confirm its not about fetching data.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, January 4, 2019 3:12 PM

All replies

  • User180523 posted

    You proved <FormatedText> for the Label and provide each differently colored or styled area as a span. Its explained in the documentation for Label https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/text/label

    Friday, January 4, 2019 3:06 PM
  • User319859 posted

    Hi @ClintStLaurent ,

    As explained in my post, I did used the FormatedText property in a first place, but using it lead to slow display of the informations. Therefore I am looking for another solution. Any idea ?

    Thank you

    Friday, January 4, 2019 3:08 PM
  • User180523 posted

    I'd be interested to really test the lag. I've never seen a performance problem with it. But I'm not putting more than 20 or so uses of it on a page. Are you doing EXTENSIVE number of these? Or could the delay really be coming from binding or fetching data?

    I guess my first performance test would be to create a number of such formatted labeles using static, hard-coded text - just as a test - to confirm its not about fetching data.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, January 4, 2019 3:12 PM
  • User319859 posted

    My listing is a pagination system so there is no more than 20 users in any case.

    I see your point. I am going to test this and will come back to you ASAP.

    One more time, thank you for everything !

    Friday, January 4, 2019 3:19 PM
  • User180523 posted

    I just ran across this... Maybe it relates... But apparently TabbedPages have an inherent performance issue. Are you doing this on tabbed pages by chance? https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/tabbed-page

    Friday, January 4, 2019 3:30 PM
  • User319859 posted

    I tested with a sample and the FormattedText is working fine with a hard coded AND a binded value !

    The lag must come from the fact that my DataTemplate is containing a lot of elements... I may need to review it.

    Otherwise, my page is not part of a TabbedPage. ;) I will keep investigate and keep you in the loop.

    Friday, January 4, 2019 4:09 PM
  • User319859 posted

    Hi @ClintStLaurent ,

    I come back to you after my recent investigations.

    As I said into my previous message, using the FormattedText is working fine into a sample therefore I started to simplify my list's configuration and its UI in hope to find the lag's origin.

    At first, I thought that the issue was coming from the RecycleElement argument since when I commented it, the list would be smoother, but then I read back the next documentation (https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/listview/performance) and I knew I did well to set it.

    So I started to simplify my DataTemplate and removed most of the StackLayouts inside the main Grid. Final result: the list is smooth as f* !!

    Thank you for your help and wish you a great week !

    Monday, January 7, 2019 10:26 AM
  • User76049 posted

    @MT_WSM said: Hi @ClintStLaurent ,

    I come back to you after my recent investigations.

    As I said into my previous message, using the FormattedText is working fine into a sample therefore I started to simplify my list's configuration and its UI in hope to find the lag's origin.

    At first, I thought that the issue was coming from the RecycleElement argument since when I commented it, the list would be smoother, but then I read back the next documentation (https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/listview/performance) and I knew I did well to set it.

    So I started to simplify my DataTemplate and removed most of the StackLayouts inside the main Grid. Final result: the list is smooth as f* !!

    Thank you for your help and wish you a great week !

    I try and avoid Stacklayout's in ViewCells as the layout calculations can be costly, using Grid's generally is a better approach if the ViewCell has a more complex layout.

    Monday, January 7, 2019 10:39 AM
  • User319859 posted

    Hi @NMackay ,

    I will keep that in mind. Thank you for your message ! :)

    Tuesday, January 8, 2019 7:49 AM