溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

.NET?MAUI項目中怎么創建超鏈接

發布時間:2022-03-28 15:52:22 來源:億速云 閱讀:267 作者:iii 欄目:開發技術

本篇內容介紹了“.NET MAUI項目中怎么創建超鏈接”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

.NET MAUI Preview 13預覽版中,.NET MAUI 支持帶標簽控件的格式化文本。

標簽中的格式化文本

標簽是顯示帶或不帶文本環繞的文本的視圖。使用格式化文本功能(現在位于單個標簽中),您可以使用不同的 span 元素為每個設置選擇多個選項。
例如,您可以對單個標簽中的單詞應用單獨的顏色。這將使標簽更具裝飾性。
Span 元素支持以下選項:

  • CharacterSpacing

  • FontAttributes

  • FontFamily

  • FontSize

  • TextColor

  • TextTransform.Lowercase

  • TextTransform.Uppercase

  • TextDecorations.Underline

  • TextDecorations.Strikethrough

<Label Margin="10" LineHeight="2">
 <Label.FormattedText>
  <FormattedString>
   <Span Text=".NET MAUI Label with Text Formatting in Preview 13 " FontSize="20" />
   <Span Text="Character Spacing - " FontSize="14" TextColor="Black"/>
   <Span Text=" Hello World! " FontSize="14" CharacterSpacing="12" />
   <Span Text="Font Attributes - " FontSize="14" TextColor="Black"/>
   <Span Text=" Hello World! " FontSize="14" FontAttributes="Bold"/>
   <Span Text="Font Size - " FontSize="14" TextColor="Black"/>
   <Span Text=" Hello World! " FontSize="18"/>
   <Span Text="Font Family - " FontSize="14" TextColor="Black"/>
   <Span Text=" Hello World! " FontSize="14" FontFamily="Matura MT Script Capitals" />
   <Span Text="Text Color - " FontSize="14" TextColor="Black"/>
   <Span Text=" Hello World! " FontSize="14" TextColor="Red"/>
   <Span Text="Lowercase - " FontSize="14" TextColor="Black"/>
   <Span Text=" Hello World! " FontSize="14" TextTransform="Lowercase"/>
   <Span Text="Uppercase - " FontSize="14" TextColor="Black"/>
   <Span Text=" Hello World! " FontSize="14" TextTransform="Uppercase" />
   <Span Text="Strikethrough - " FontSize="14" TextColor="Black"/>
   <Span Text=" Hello World! " FontSize="14" TextDecorations="Strikethrough"/>
   <Span Text="Underline - " FontSize="14" TextColor="Black"/>
   <Span Text=" Hello World! " FontSize="14" TextDecorations="Underline" />
  </FormattedString>
 </Label.FormattedText>
</Label>

.NET?MAUI項目中怎么創建超鏈接

使用標簽的格式化文本功能創建超鏈接 UI

我將使用兩個選項,TextColor和TextDecorations.Undercomings.Undercoming,創建一個具有超鏈接UI的標簽。

創建可重用超鏈接類

創建了一個名為 HyperlinkUI 的類,該類派生自 span,并在其中添加了一個名為 LinkUrl 的可綁定屬性。
由于 span 繼承了 GestureElement,因此您可以添加 Gesture 識別器以使用 LinkUrl 屬性進行導航。
請參閱下面的代碼示例。

public class HyperlinkUI : Span
{
  public static readonly BindableProperty LinkUrlProperty =
   BindableProperty.Create(nameof(LinkUrl), typeof(string), typeof(HyperlinkUI), null);
  
  public string LinkUrl
  {
    get
    {
      return (string)GetValue(LinkUrlProperty);
    }
    set
    {
      SetValue(LinkUrlProperty, value);
    }
  }

   public HyperlinkUI()
   {
      ApplyHyperlinkAppearance();
   }

   void ApplyHyperlinkAppearance()
   {
      this.TextColor = Color.FromArgb("#0000EE");
      this.TextDecorations = TextDecorations.Underline;
   }

   void CreateNavgigationCommand()
   {
      // 由于 Span 繼承了 GestureElement,因此您可以添加 Gesture Recognizer 以使用 LinkUrl 進行導航
   }
}

現在,您可以將此超鏈接UI用作標簽中的跨度元素。我們可以將整個文本或部分文本顯示為超鏈接文本。請參閱下面的代碼示例。

<Label Margin="10" LineHeight="2" InputTransparent="False" TextColor="Black">
 <Label.FormattedText>
  <FormattedString>
   <Span Text="Click "/>
   <local:HyperlinkUI Text="here" LinkUrl="https://docs.microsoft.com/xamarin/"/>
   <Span Text=" to learn more about Syncfusion .NET MAUI Controls."/>
  </FormattedString>
 </Label.FormattedText>
</Label>

.NET?MAUI項目中怎么創建超鏈接

“.NET MAUI項目中怎么創建超鏈接”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女