XamarinXAML語言中如何實(shí)現(xiàn)模板視圖TemplatedView-創(chuàng)新互聯(lián)

這篇文章給大家分享的是有關(guān)Xamarin XAML語言中如何實(shí)現(xiàn)模板視圖TemplatedView的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),皇姑企業(yè)網(wǎng)站建設(shè),皇姑品牌網(wǎng)站建設(shè),網(wǎng)站定制,皇姑網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,皇姑網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。

模板視圖TemplatedView

與模板頁面相對的是TemplatedView,它被稱為模板視圖,它的功能和模板頁面類似,也是用來顯示控件模板的,只不過比模板頁面更加靈活。TemplatedView提供ControlTemplate屬性,實(shí)現(xiàn)對控件模板的關(guān)聯(lián),從而展現(xiàn)對應(yīng)的界面。

【示例14-6:TemplatedViewDemo】以下將使用模板視圖顯示控件模板,并實(shí)現(xiàn)模板的切換。具體的操作步驟如下:

(1)打開App.xaml文件,編寫代碼,實(shí)現(xiàn)在應(yīng)用程序級別中構(gòu)建控件模板,代碼如下:

  • <?xml version="1.0" encoding="utf-8" ?>

  • <Application xmlns="/tupian/20230522/xamarin

  •              xmlns:x="/tupian/20230522/error.aspx

  •              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="空山新雨后,天氣晚來秋。"

  •                        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>

  • <!--構(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語言中如何實(shí)現(xiàn)模板視圖TemplatedView”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

網(wǎng)站標(biāo)題:XamarinXAML語言中如何實(shí)現(xiàn)模板視圖TemplatedView-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://muchs.cn/article2/dcpeic.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、用戶體驗(yàn)網(wǎng)站策劃、建站公司自適應(yīng)網(wǎng)站、標(biāo)簽優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)