Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to build ControlTemplate Control template in Xamarin XAML language

Shulou Source: shulou.com Published: 2022-06-01 10:13:29 09月26日 Update

Editor to share with you how to build ControlTemplate control templates in Xamarin XAML language. I hope you will get something after reading this article. Let's discuss it together.

Control template ControlTemplate

ControlTemplate has been introduced since Xamarin.Forms 2.1.0. ControlTemplate, known as the control template, separates the appearance and content of the page, making it easier for developers to create theme-based pages.

Build a control template

Control templates can be built at the application level or at the page level. These two build methods are explained below.

1. Application level build

If developers want to build control templates at the application level, they must first add ResourceDictionary to the App class, and then implement the template construction in ResourceDictionary. Its grammatical form is as follows:

……

Where KeyName specifies a dictionary key that refers to the control template.

After building the template, we need to display the template control, and we need a view that can be templated. There will be a ControlTemplate property in each of these views. After you set this property to the control template you created, the control template can be displayed. There are currently only four views in Xamarin.Forms that contain the ControlTemplate property, which are as follows:

ContentPage: content pa

ContentView: content view

TemplatedPage: template page

TemplatedView: template view

[example 14-3:ControlTemplateDemo] the control template will be built at the application level to switch application themes. The specific steps are as follows:

(1) Open the App.xaml file, write the code, and build the control template at the application level, as follows:

In this code, we build two control templates, one for the TealTemplate control template and the other for the AquaTemplate control template.

After reading this article, I believe you have some understanding of "how to build ControlTemplate control templates in Xamarin XAML language". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Templates controls applications programs levels views applications pages Code content Properties languages two themes developers articles developers only appearance Dictionary Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Huawei Redmi Docker Shulou Tech Info