zoukankan      html  css  js  c++  java
  • Xamarin XAML语言教程构建ControlTemplate控件模板 (三)

    Xamarin XAML语言教程构建ControlTemplate控件模板 (三)

    (3)打开MainPage.xaml.cs文件,编写代码,实现主题的切换功能。代码如下:

     

    • using System;
    • using System.Collections.Generic;
    • using System.Linq;
    • using System.Text;
    • using System.Threading.Tasks;
    • using Xamarin.Forms;
    • namespace ControlTemplateDemo
    • {
    •     public partial class MainPage : ContentPage
    •     {
    •         bool originalTemplate = true;
    •         ControlTemplate tealTemplate;
    •         ControlTemplate aquaTemplate;
    •         public MainPage()
    •         {
    •             InitializeComponent();
    •             //实例化控件模板
    •             tealTemplate = (ControlTemplate)Application.Current.Resources["TealTemplate"];
    •             aquaTemplate = (ControlTemplate)Application.Current.Resources["AquaTemplate"];
    •         }
    •         //实现模板的切换
    •         void OnButtonClicked(object sender, EventArgs e)
    •         {
    •             originalTemplate = !originalTemplate;
    •             contentView.ControlTemplate = (originalTemplate) ? tealTemplate : aquaTemplate;
    •         }
    •     }
    • }

    此时运行程序,会看到如图14.12~14.14所示的效果。当开发者轻拍“改变主题”按钮后,会看到如图14.15~14.17所示的效果。

  • 相关阅读:
    jquery对标签属性操作
    将RichTextBox的内容直接写入数据库:
    zendstdio的智能提示功能
    LINQ操作数组(交集,并集,差集,最值,平均,去重复)
    包含的语句
    网站后台弱口令搜集(转自老白)
    委托之异步
    C# 操作超时正常还是错
    cookie转coontoin
    Qt编写自定义控件17-按钮进度条
  • 原文地址:https://www.cnblogs.com/daxueba-ITdaren/p/7200014.html
Copyright © 2011-2022 走看看