.NET?MAUI項(xiàng)目中創(chuàng)建超鏈接
.NET MAUI Preview 13預(yù)覽版中,.NET MAUI 支持帶標(biāo)簽控件的格式化文本。
標(biāo)簽中的格式化文本
標(biāo)簽是顯示帶或不帶文本環(huán)繞的文本的視圖。使用格式化文本功能(現(xiàn)在位于單個標(biāo)簽中),您可以使用不同的 span 元素為每個設(shè)置選擇多個選項(xiàng)。
例如,您可以對單個標(biāo)簽中的單詞應(yīng)用單獨(dú)的顏色。這將使標(biāo)簽更具裝飾性。
Span 元素支持以下選項(xiàng):
- 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>
使用標(biāo)簽的格式化文本功能創(chuàng)建超鏈接 UI
我將使用兩個選項(xiàng),TextColor和TextDecorations.Undercomings.Undercoming,創(chuàng)建一個具有超鏈接UI的標(biāo)簽。
創(chuàng)建可重用超鏈接類
創(chuàng)建了一個名為 HyperlinkUI 的類,該類派生自 span,并在其中添加了一個名為 LinkUrl 的可綁定屬性。
由于 span 繼承了 GestureElement,因此您可以添加 Gesture 識別器以使用 LinkUrl 屬性進(jìn)行導(dǎo)航。
請參閱下面的代碼示例。
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 進(jìn)行導(dǎo)航 } }
現(xiàn)在,您可以將此超鏈接UI用作標(biāo)簽中的跨度元素。我們可以將整個文本或部分文本顯示為超鏈接文本。請參閱下面的代碼示例。
<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>
到此這篇關(guān)于.NET MAUI項(xiàng)目中創(chuàng)建超鏈接的文章就介紹到這了。希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
ASP.NET小結(jié)之MVC, MVP, MVVM比較以及區(qū)別(二)
上一篇得到大家的關(guān)注,非常感謝。由于自己對于這些模式的理解也是有限,對于MVC,MVP,MVVM這些模式的比較,是結(jié)合自己的理解,一些地方不一定準(zhǔn)確,需要的朋友可以參考下2014-05-05ASP.NET MVC驗(yàn)證碼功能實(shí)現(xiàn)代碼
ASP.NET MVC驗(yàn)證碼功能實(shí)現(xiàn)代碼,需要的朋友可以參考一下2013-06-06.NET?CORE?鑒權(quán)的實(shí)現(xiàn)示例
本文主要介紹了.NET?CORE?鑒權(quán)的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-02-02ASP.NET Core程序發(fā)布到Linux生產(chǎn)環(huán)境詳解
這篇文章主要為大家詳細(xì)介紹了ASP.NET Core程序發(fā)布到Linux生產(chǎn)環(huán)境,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04asp.net異步獲取datatable并顯示的實(shí)現(xiàn)方法
這篇文章主要介紹了asp.net異步獲取datatable并顯示的實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了asp.net一步操作datatable的相關(guān)技巧,需要的朋友可以參考下2016-03-03The remote procedure call failed and did not execute的解決辦法
打開IIS隨便訪問一個.asp文件,提示The remote procedure call failed and did not execute2009-11-11ASP.NET中利用存儲過程實(shí)現(xiàn)模糊查詢
ASP.NET中利用存儲過程實(shí)現(xiàn)模糊查詢...2006-09-09