Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use ContentView view as the parent class of custom view in Xamarin XAML language

Shulou Source: shulou.com Published: 2022-06-01 10:11:37 10月01日 Update

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!

Tags: View code color layout file language complexity content pattern article value interest name internal partner attribute effect more step Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Apple macOS Linux OPPO Reno