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 use ContentView view as the parent class of custom view in Xamarin XAML language

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces how to use ContentView view as the parent class of custom view in Xamarin XAML language. It is very detailed and has certain reference value. Friends who are interested must finish it!

Parent class of custom view: ContentView view can be used as the parent class of custom view.

[example 14-2] A color view will be customized below. The specific steps are as follows:

(1) create a Forms Xaml View file named ColorView.

(2) Open the ColorView.xaml file, write code, and build a custom color view. The code is as follows:

(3) Open the ColorView.xaml.cs file, write the code, and realize some properties related to the color view. The code is as follows:

Using System

Using System.Collections.Generic

Using System.Linq

Using System.Text

Using System.Threading.Tasks

Using Xamarin.Forms

Namespace ContentViewCustomControls

{

Public partial class ColorView: ContentView

{

String colorName

ColorTypeConverter colorTypeConv = new ColorTypeConverter ()

Public ColorView ()

{

InitializeComponent ()

}

/ / Color name

Public string ColorName

{

Set

{

ColorName = value

ColorNameLabel.Text = value

Color color = (Color) colorTypeConv.ConvertFromInvariantString (colorName)

BoxView.Color = color

ColorValueLabel.Text = String.Format ("{0:X2}-{1:X2}-{2:X2}"

(int) (255 * color.R)

(int) (255 * color.G)

(int) (255 * color.B))

}

Get

{

Return colorName

}

}

}

}

(4) Open the MainPage.xaml file, write code, and realize the layout of the content page through the color view. The code is as follows:

When you run the program at this point, you will see the effect shown in figure 14.10-14.11.

(5) build more complex layout patterns: you can include views and layouts in ContentView to build more complex layout patterns.

These are all the contents of the article "how to use ContentView views as the parent of custom views in the Xamarin XAML language". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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

Internet Technology

Wechat

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

12
Report