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

MT_WSMMT_WSM ✭✭FRMember ✭✭

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,

Tagged:

Best Answer

  • ClintStLaurentClintStLaurent ✭✭✭✭✭ US ✭✭✭✭✭
    Accepted Answer

    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.

Answers

  • ClintStLaurentClintStLaurent ✭✭✭✭✭ USUniversity ✭✭✭✭✭
    edited January 4

    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

  • MT_WSMMT_WSM ✭✭ FRMember ✭✭

    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

  • ClintStLaurentClintStLaurent ✭✭✭✭✭ USUniversity ✭✭✭✭✭
    Accepted Answer

    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.

  • MT_WSMMT_WSM ✭✭ FRMember ✭✭

    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 !

  • ClintStLaurentClintStLaurent ✭✭✭✭✭ USUniversity ✭✭✭✭✭

    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

  • MT_WSMMT_WSM ✭✭ FRMember ✭✭
    edited January 4

    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.

  • MT_WSMMT_WSM ✭✭ FRMember ✭✭

    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 !

  • NMackayNMackay mod GBInsider, University mod

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

  • MT_WSMMT_WSM ✭✭ FRMember ✭✭

    Hi @NMackay ,

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

Sign In or Register to comment.