how to implement similar inner HTML functionality in Xamarin

48 views Asked by At

questions containing text and hyperlink together in the above picture we can see that we have both text and picture simultaneously we achieved this functionality using innerhtml in angular code for innerhtml we have used is <span [innerHTML]="question.question">
we have to achieved similar functionality in Xamarin how can we achieved this ,

code that we are using in Xamarin is for catering question from backend is

   `    `<StackLayout
       Grid.Column="1"
       Margin="5,0,0,0"
        VerticalOptions="CenterAndExpand">
       <Label
       FontSize="10"
        IsVisible="{Binding IsOptional}"
       LineHeight="1.6"
       Text="{resource:Translate OptionalLabelUpperCase}"
       TextColor="{StaticResource PlaceholderLightGrey}" />
       <Label
       FontSize="14"
       LineBreakMode="TailTruncation"
       MaxLines="2"
       Text="{Binding Question}"
       TextColor="{StaticResource OIANavy1}" />
      </StackLayout>`

what chnages we need to perform such that it can cater the information both for text and hyperlink as given in the image, actually we are entering data on text editor from web portal and in the text editor we have functionality to enter both text and hyperlink together. We are getting this informtaion on some another portal but in backend it is getting saved as string .

for web portal we used innerhtml code :

<label class="question-label mb-0"><span 
      [innerHTML]="question.question"></span></label>

to cater this information but on agent portal I am not able to see the hyperlink and application gets crashed if we change anything what changes need to perfrom so that it can work for xamarin appliction too. Basically I need to apply same functionality of innerhtml in case of xamarin

1

There are 1 answers

0
Liyun Zhang - MSFT On

First of all, you can read the official document about the Hyperlinks for the Xamarin Label. It show the details steps to display the hyperlink in the xamarin.

You can use the Label and the Span to display the text as a hyperlink. And then you can use TapGestureRecognizer to deal with the hyperlink clicked event:

  1. If it is a web url, you can use Launcher.OpenAsync(Url) to open it in the browser app.
  2. If it is an embedded html file, you can renderer it with the webview.