這篇文章給大家分享的是有關(guān)Xamarin XAML語(yǔ)言中如何實(shí)現(xiàn)模板視圖TemplatedView的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名與空間、網(wǎng)站空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、柞水網(wǎng)站維護(hù)、網(wǎng)站推廣。
與模板頁(yè)面相對(duì)的是TemplatedView,它被稱為模板視圖,它的功能和模板頁(yè)面類似,也是用來(lái)顯示控件模板的,只不過(guò)比模板頁(yè)面更加靈活。TemplatedView提供ControlTemplate屬性,實(shí)現(xiàn)對(duì)控件模板的關(guān)聯(lián),從而展現(xiàn)對(duì)應(yīng)的界面。
【示例14-6:TemplatedViewDemo】以下將使用模板視圖顯示控件模板,并實(shí)現(xiàn)模板的切換。具體的操作步驟如下:
(1)打開(kāi)App.xaml文件,編寫代碼,實(shí)現(xiàn)在應(yīng)用程序級(jí)別中構(gòu)建控件模板,代碼如下:
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TemplatedViewDemo.App">
<Application.Resources>
<ResourceDictionary>
<!--構(gòu)建控件模板-->
<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="空山新雨后,天氣晚來(lái)秋。"
FontSize="18"/>
<Label Text="明月松間照,清泉石上流。"
FontSize="18"/>
<Label Text="竹喧歸浣女,蓮動(dòng)下漁舟。"
FontSize="18"/>
<Label Text="隨意春芳歇,王孫自可留。"
FontSize="18"/>
</StackLayout>
</Frame>
<Button Command="{TemplateBinding Parent. CommandEnglish}"
Text="Enter English Template" />
</StackLayout>
</StackLayout>
</ControlTemplate>
<!--構(gòu)建控件模板-->
<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>
在此代碼中,我們構(gòu)建了兩個(gè)控件模板,一個(gè)為ChineseTemplate控件模板,另一為EnglishTemplate控件模板。
感謝各位的閱讀!關(guān)于“Xamarin XAML語(yǔ)言中如何實(shí)現(xiàn)模板視圖TemplatedView”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
本文名稱:XamarinXAML語(yǔ)言中如何實(shí)現(xiàn)模板視圖TemplatedView
文章位置:http://muchs.cn/article16/ijdggg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站、做網(wǎng)站、品牌網(wǎng)站制作、靜態(tài)網(wǎng)站、ChatGPT、網(wǎng)頁(yè)設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)