Xamarin XAML語言教程模板檢視TemplatedView(一)
Xamarin XAML語言教程模板檢視TemplatedView(一)
模板檢視TemplatedView
與模板頁面相對的是TemplatedView,它被稱為模板檢視,它的功能和模板頁面類似,也是用來顯示控制元件模板的,只不過比模板頁面更加靈活。TemplatedView提供ControlTemplate屬性,實現對控制元件模板的關聯,從而展現對應的介面。
【示例14-6:TemplatedViewDemo】以下將使用模板檢視顯示控制元件模板,並實現模板的切換。具體的操作步驟如下:
(1)開啟App.xaml檔案,編寫程式碼,實現在應用程式級別中構建控制元件模板,程式碼如下:
- <?xml version="1.0" encoding="utf-8" ?>
- <Application xmlns=""
- xmlns:x=""
- x:Class="TemplatedViewDemo.App">
- <Application.Resources>
- <ResourceDictionary>
- <!--構建控制元件模板-->
- <ControlTemplate x:Key="ChineseTemplate">
- <StackLayout>
- <StackLayout VerticalOptions="End">
- <BoxView Color="Aqua" />
- </StackLayout>
- <StackLayout Spacing="35"
- VerticalOptions="CenterAndExpand" >
- <Frame OutlineColor="Accent">
- <StackLayout Spacing="20"
- VerticalOptions="CenterAndExpand"
- HorizontalOptions="Center">
- <Label Text="山居秋暝"
- FontSize="30"
- FontAttributes="Bold"
- HorizontalOptions="Center"/>
- <Label Text="空山新雨後,天氣晚來秋。"
- FontSize="18"/>
- <Label Text="明月松間照,清泉石上流。"
- FontSize="18"/>
- <Label Text="竹喧歸浣女,蓮動下漁舟。"
- FontSize="18"/>
- <Label Text="隨意春芳歇,王孫自可留。"
- FontSize="18"/>
- </StackLayout>
- </Frame>
- <Button Command="{TemplateBinding Parent. CommandEnglish}"
- Text="Enter English Template" />
- </StackLayout>
- </StackLayout>
- </ControlTemplate>
- <!--構建控制元件模板-->
- <ControlTemplate x:Key="EnglishTemplate">
- <StackLayout>
- <StackLayout VerticalOptions="End">
- <BoxView Color="Green" />
- </StackLayout>
- <StackLayout Spacing="35"
- VerticalOptions="CenterAndExpand" >
- <Frame OutlineColor="Accent">
- <Label Text="your life only lasts for a few decades, so be sure that you don\'t leave any regrets. laugh or cry as you like, and it‘s meaningless to oppress yourself."
- FontAttributes="Bold"
- FontSize="18"/>
- </Frame>
- <Button Command="{TemplateBinding Parent.CommandChinese}"
- Text="Enter Chinese Template" />
- </StackLayout>
- </StackLayout>
- </ControlTemplate>
- </ResourceDictionary>
- </Application.Resources>
- </Application>
在此程式碼中,我們構建了兩個控制元件模板,一個為ChineseTemplate控制元件模板,另一為EnglishTemplate控制元件模板。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29597077/viewspace-2142721/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 剖析XAML語言
- Xamarin Essentials教程語音播報TextToSpeech
- Xamarin Essentials教程檢查網路連通性Connectivity
- Linux 檢視設定系統語言(轉)Linux
- 20天學會go語言視訊教程Go
- Django的檢視和模板Django
- 論如何自己寫一個Python的模板語言Python
- smarty模板引擎視訊教程
- Solidity語言學習筆記————27、檢視函式Solid筆記函式
- Spring 指南(瞭解檢視模板)Spring
- R語言:KEGG富集、視覺化教程,附程式碼R語言視覺化
- 好程式設計師Java教程:SQL語言之檢視程式設計師JavaSQL
- django 模板語言的註釋操作Django
- Visual Studio系列教程:使用XAML工具建立使用者介面(一)
- 視覺語言如何準確的表達(附影片教程)視覺
- Xamarin Essentials教程陀螺儀GyroscopeROS
- Xamarin Essentials教程磁力計Magnetometer
- django模板怎麼配置檢視和urlDjango
- Django基礎三之路由、檢視、模板Django路由
- Prolog 語言入門教程
- C語言 Make命令教程C語言
- GO語言敏感詞檢測Go
- SpringBoot教程——檢視閱讀Spring Boot
- Servlet 教程——檢視閱讀Servlet
- JDBC教程——檢視閱讀JDBC
- 視覺語言兩開花!谷歌提出全新視覺語言橋樑視覺谷歌
- Xamarin Essentials教程開啟檔案
- Xamarin Essentials教程地理定位Geolocation
- Xamarin Essentials教程安全儲存SecureStorageREST
- PHP歷理 檢視模板和標籤庫PHP
- C語言系列之 指標強化與應用視訊教程C語言指標
- go語言入門教程分享:第一個程式:HelloWorldGo
- R語言的入門教程R語言
- go語言快速入門教程Go
- C語言精品影片教程大全C語言
- 多語言檢測工具實踐
- C語言教程——03 C語言結構C語言
- Spring MVC教程——檢視閱讀SpringMVC
- 3分鐘短文:Laravel模板,也支援一般程式語言的語法結構了Laravel