網(wǎng)站首頁 編程語言 正文
.NET MAUI Preview 13預(yù)覽版中,.NET MAUI 支持帶標簽控件的格式化文本。
標簽中的格式化文本
標簽是顯示帶或不帶文本環(huán)繞的文本的視圖。使用格式化文本功能(現(xiàn)在位于單個標簽中),您可以使用不同的 span 元素為每個設(shè)置選擇多個選項。
例如,您可以對單個標簽中的單詞應(yīng)用單獨的顏色。這將使標簽更具裝飾性。
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>
使用標簽的格式化文本功能創(chuàng)建超鏈接 UI
我將使用兩個選項,TextColor和TextDecorations.Undercomings.Undercoming,創(chuàng)建一個具有超鏈接UI的標簽。
創(chuàng)建可重用超鏈接類
創(chuàng)建了一個名為 HyperlinkUI 的類,該類派生自 span,并在其中添加了一個名為 LinkUrl 的可綁定屬性。
由于 span 繼承了 GestureElement,因此您可以添加 Gesture 識別器以使用 LinkUrl 屬性進行導(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 進行導(dǎo)航 } }
現(xiàn)在,您可以將此超鏈接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>
原文鏈接:https://www.cnblogs.com/zh7791/p/15993131.html
相關(guān)推薦
- 2022-06-11 利用Nginx實現(xiàn)URL重定向的簡單方法_nginx
- 2022-11-26 React?useReducer終極使用教程_React
- 2022-04-14 CMake編譯中的庫文件和頭文件鏈接你了解嗎_C 語言
- 2022-06-06 基于VSTS的Xamarin.Android持續(xù)集成步驟詳解_Android
- 2021-11-25 Linux命令unzip詳解_Linux
- 2022-10-19 Python?變量教程私有變量詳解_python
- 2022-11-08 Go讀取文件與寫入文件的三種方法操作指南_Golang
- 2022-05-27 Docker常見命令介紹_docker
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支