see docs:
Issue with Label in ListView: Unable to Navigate to URLs in HTML Text with Dynamic Data
'm currently working on a Microsoft Maui application where I have a ListView containing labels. These labels display dynamically generated HTML-formatted text obtained from data, and within this text, there could be multiple hyperlinks to external URLs. Despite correctly highlighting the URLs within the Label component, I'm encountering difficulties implementing functionality that allows users to navigate to these URLs in an external web browser. Could you please provide guidance on how to implement this feature effectively for dynamically generated HTML text containing multiple URLs? Specifically, I need assistance on enabling hyperlink navigation within the Label component in a ListView, allowing users to open any URL in an external web browser when clicked.
Thank you for your assistance!
** --update
To provide some context, here's a snippet of the code I'm currently using for the Label component within my ListView: C#Copy
<Label TextType="Html">
<![CDATA[
<p>Hi Google - <a class="e-rte-anchor" href="https://www.google.com/" title="Google" >Google Link</a></p><p>Please check the above URL.</p><p>Please check <a class="e-rte-anchor" href="https://help.syncfusion.com/maui/carousel-view/populating-data?cs-save-lang=1&cs-lang=xaml" title="Syncfusion Maui" target="_blank">Syncfusion</a> Maui.</p>
]]>
</Label>
In this implementation, I'm able to display HTML-formatted text containing multiple URLs within the Label component. However, I'm struggling to capture click events on these URLs and retrieve the URL that was clicked. Could you please provide guidance on how I can capture click events for each individual URL within the HTML text and retrieve the specific URL that was clicked? Any assistance you can provide would be greatly appreciated. Thank you,
Developer technologies | .NET | .NET MAUI
Developer technologies | .NET | Other
3 answers
Sort by: Most helpful
-
Bruce (SqlWork.com) 77,766 Reputation points Volunteer Moderator
2024-02-09T21:22:33.24+00:00 -
Shahid Abbas 5 Reputation points
2024-02-14T13:19:24.7366667+00:00 Thank you for your attention to my inquiry. To provide some context, here's a snippet of the code I'm currently using for the Label component within my ListView: C#Copy
<Label TextType="Html"> <![CDATA[ <p>Hi Google - <a class="e-rte-anchor" href="https://www.google.com/" title="Google" >Google Link</a></p><p>Please check the above URL.</p><p>Please check <a class="e-rte-anchor" href="https://help.syncfusion.com/maui/carousel-view/populating-data?cs-save-lang=1&cs-lang=xaml" title="Syncfusion Maui" target="_blank">Syncfusion</a> Maui.</p> ]]> </Label>
In this implementation, I'm able to display HTML-formatted text containing multiple URLs within the Label component. However, I'm struggling to capture click events on these URLs and retrieve the URL that was clicked. Could you please provide guidance on how I can capture click events for each individual URL within the HTML text and retrieve the specific URL that was clicked? Any assistance you can provide would be greatly appreciated. Thank you,
-
Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
2024-02-15T10:25:13.7566667+00:00 Hello, You could turn the text into hyperlinks and add a
TapGestureRecognizer
, then open the url in web browser.Please see the Create a hyperlink section in the Label doc:
The
TapCommand
executes theLauncher.OpenAsync
method, passing theTapGestureRecognizer.CommandParameter
property value as a parameter. TheLauncher.OpenAsync
method opens the URL in a web browser. Best Regards,Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.