Xamarin XAML Language Tutorial Building ControlTemplate control Templates (iv)

Source: Internet
Author: User

Xamarin XAML Language Tutorial Building ControlTemplate control Templates (iv)

2. Building a control template at the page level

If the developer wants to build the control template at the page level, you first have to add resourcedictionary to the page, and then implement the template build in ResourceDictionary, with the following syntax:

    • <Page>
    • <Page.Resources>
    • <ResourceDictionary>
    • <controltemplate x:key= "KeyName" >
    • ......
    • </ControlTemplate>
    • </ResourceDictionary>
    • </Page.Resources>
    • </Page>

Where page represents the pages and the child classes of the page. KeyName is used to specify a dictionary key, which refers to the control template.

Example 14-4:controltemplatecontentpage the following will build the control template in the content page. The code is as follows:

  • <?xml version= "1.0" encoding= "Utf-8"?>
  • <contentpage xmlns= "Http://xamarin.com/schemas/2014/forms"
  • xmlns:x= "Http://schemas.microsoft.com/winfx/2009/xaml"
  • Xmlns:local= "Clr-namespace:controltemplatecontentpage"
  • x:class= "Controltemplatecontentpage.mainpage" >
  • <ContentPage.Resources>
  • <ResourceDictionary>
  • <!--Building Control templates--
  • <controltemplate x:key= "Tealtemplate" >
  • <stacklayout verticaloptions= "Centerandexpand"
  • Spacing= "20"
  • Padding= ">"
  • <entry placeholder= "Username"/>
  • <entry placeholder= "Password"
  • ispassword= "True"/>
  • <button text= "Click here to Log in"/>
  • <contentpresenter/>
  • </StackLayout>
  • </ControlTemplate>
  • </ResourceDictionary>
  • </ContentPage.Resources>
  • <contentview x:name= "Contentview"
  • Padding= "0,20,0,0"
  • controltemplate= "{StaticResource tealtemplate}">
  • <frame outlinecolor= "Accent" >
  • <label text= "Please enter your account number and the corresponding password after confirming the safety of your environment."
  • Fontattributes= "Bold"
  • Fontsize= "/>"
  • </Frame>
  • </ContentView>
  • </ContentPage>

When you run the program, you see the effect shown in 14.18~14.20.

Xamarin XAML Language Tutorial Building ControlTemplate control Templates (iv)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.