Xamarin XAML Language Tutorial template view Templatedview (ii)

Source: Internet
Author: User

Xamarin XAML Language Tutorial template view Templatedview (ii)

(2) Open the MainPage.xaml file, write the code, and apply the built control template to the Templatedview. 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:templatedviewdemo"
    • x:class= "Templatedviewdemo.mainpage" >
    • <templatedview x:name= "Templatedview"
    • Padding= "0,20,0,0"
    • controltemplate= "{StaticResource chinesetemplate}" >
    • </TemplatedView>
    • </ContentPage>

(3) Open the MainPage.xaml.cs file, write code, and implement the switch function of the control template. The code is as follows:

  • Using System;
  • Using System.Collections.Generic;
  • Using System.Linq;
  • Using System.Text;
  • Using System.Threading.Tasks;
  • Using System.Windows.Input;
  • Using Xamarin.Forms;
  • Namespace Templatedviewdemo
  • {
  • public partial class Mainpage:contentpage
  • {
  • ControlTemplate Chinesetemplate;
  • ControlTemplate Englishtemplate;
  • Public ICommand commandenglish {private set; get;}
  • Public ICommand Commandchinese {private set; get;}
  • Public MainPage ()
  • {
  • Commandenglish = new Command (() = Onenterenglishtemplate ());
  • Commandchinese = new Command (() = Onenterchinesetemplate ());
  • InitializeComponent ();
  • Chinesetemplate = (ControlTemplate) application.current.resources["Chinesetemplate"];
  • Englishtemplate = (ControlTemplate) application.current.resources["Englishtemplate"];
  • }
  • Set as Englishtemplate control template
  • Public void Onenterenglishtemplate ()
  • {
  • Templatedview.controltemplate = englishtemplate;
  • }
  • Set as Chinesetemplate control template
  • public void Onenterchinesetemplate ()
  • {
  • Templatedview.controltemplate = chinesetemplate;
  • }
  • }
  • }

When you run the program, you see the effect shown in 14.21~14.23. When the developer taps the Enter English template button, you will see the effect shown in 14.24~14.26. When the developer taps the Enter Chinese template button, you'll see the effect shown in 14.21~14.23.

Xamarin XAML Language Tutorial template view Templatedview (ii)

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.