dotMorten / MauiEx

A set of .NET MAUI controls
Apache License 2.0
225 stars 55 forks source link

Match highlighting on the results #52

Open dejanbasic opened 5 years ago

dejanbasic commented 5 years ago

Hello, I need to implement highlighting of search query on the matched results. Is there a way to do that?

dotMorten commented 5 years ago

I don't think any of the native controls used supports this, so I don't see a way to do this

dejanbasic commented 5 years ago

This is Syncfusion Xamarin.Forms Autocomplete control:

How they do this?

dotMorten commented 5 years ago

@dejanbasic I'm guessing they don't rely on native controls but custom forms control?

dotMorten commented 5 years ago

Notes: iOS example using attributed text: https://github.com/dinarajas/HighlightLabel/blob/master/classes/HighlightLabel.m

dejanbasic commented 5 years ago

I implemented my own custom solution in Xamarin.Forms, which looks like this:

Screenshot 2019-11-13 at 13 35 55

I used Entry control for search box and ListView for showing search results. I managed to highlight matched results, by using Label->FormattedText->FormattedString->Span controls, to split text into three parts: first part, highlighted text and last part.