Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create hyperlinks in .NET MAUI projects

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to create hyperlinks in a .NET MAUI project". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In the .NET MAUI Preview 13 preview, .NET MAUI supports formatted text with tagged controls.

Formatted text in tags

A label is a view that displays text with or without text wrapping. Using the formatted text feature (now in a single tag), you can use different span elements to select multiple options for each setting.

For example, you can apply separate colors to words in a single label. This will make the label more decorative.

The Span element supports the following options:

CharacterSpacing

FontAttributes

FontFamily

FontSize

TextColor

TextTransform.Lowercase

TextTransform.Uppercase

TextDecorations.Underline

TextDecorations.Strikethrough

Create a hyperlink UI using the formatted text feature of the tag

I'll use two options, TextColor and TextDecorations.Undercomings.Undercoming, to create a tag with a hyperlink UI.

Create a reusable hyperlink class

A class named HyperlinkUI is created, which is derived from span, and a bindable property named LinkUrl is added to it.

Because span inherits GestureElement, you can add a Gesture recognizer to navigate using the LinkUrl attribute.

See the following code example.

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 () {/ / because Span inherits GestureElement, you can add Gesture Recognizer to use LinkUrl for navigation}}

You can now use this hyperlink UI as a span element in the tag. We can display the whole text or part of the text as hyperlinked text. See the following code example.

That's all for "how to create hyperlinks in a .NET MAUI project". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report