99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

XamarinXAML語言中如何實(shí)現(xiàn)控件模板的模板綁定-創(chuàng)新互聯(lián)

這篇文章主要介紹Xamarin XAML語言中如何實(shí)現(xiàn)控件模板的模板綁定,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!

創(chuàng)新互聯(lián)公司專注于企業(yè)營銷型網(wǎng)站、網(wǎng)站重做改版、忻城網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5高端網(wǎng)站建設(shè)、成都做商城網(wǎng)站、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價格優(yōu)惠性價比高,為忻城等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

 控件模板的模板綁定

為了可以輕松更改控件模板中控件上的屬性值,可以在控件模板中實(shí)現(xiàn)模板綁定功能。模板綁定允許控件模板中的控件將數(shù)據(jù)綁定到公共屬性上。這時需要使用TemplateBinding。它可以將控件模板中的控件的屬性綁定到擁有控件模板的目標(biāo)視圖的父級上的可綁定屬性上。

注意:(1)TemplateBinding類似于現(xiàn)有的Binding,不同之處在于TemplateBinding的源總是自動設(shè)置為擁有控件模板的目標(biāo)視圖的父級。(2)不支持在控件模板之外使用TemplateBinding。

【示例14-5:ControlTemplateDemo】以下將以項(xiàng)目ControlTemplateDemo為基礎(chǔ),在控件模板中實(shí)現(xiàn)模板綁定功能。具體的操作步驟如下:

(1)打開MainPage.xaml文件,編寫代碼,實(shí)現(xiàn)可綁定屬性的定義。代碼如下:

  • namespace ControlTemplateDemo

  • {

  •     public partial class MainPage : ContentPage

  •     {

  •         bool originalTemplate = true;

  •         ControlTemplate tealTemplate;

  •         ControlTemplate aquaTemplate;

  •         public static readonly BindableProperty HeaderTextProperty = BindableProperty.Create("HeaderText",

  •                                                                            typeof(string),

  •                                                                            typeof(MainPage),

  •                                                                            "Knowledge is power.");

  •         public static readonly BindableProperty FooterTextProperty = BindableProperty.Create("FooterText",

  •                                                                           typeof(string),

  •                                                                           typeof(MainPage),

  •                                                                           "Xamarin.Froms XAML");

  •         public MainPage()

  •         {

  •             InitializeComponent();

  • ……                        //此處省略了對tealTemplate和aquaTemplate對象的實(shí)例化

  •         }

  •         public string HeaderText

  •         {

  •             get

  •             {

  •                 return (string)GetValue(HeaderTextProperty);

  •             }

  •         }

  •         public string FooterText

  •         {

  •             get

  •             {

  •                 return (string)GetValue(FooterTextProperty);

  •             }

  •         }

  • ……                                //此處省略了對OnButtonClicked方法的實(shí)現(xiàn)

  •     }

  • }

(2)打開App.xaml文件,編寫代碼,在第一個構(gòu)建的ControlTemplate中實(shí)現(xiàn)模板綁定功能。代碼如下:

  • <ControlTemplate x:Key="TealTemplate">

  •   <Grid>

  •     <Grid.RowDefinitions>

  •       <RowDefinition Height="0.1*" />

  •       <RowDefinition Height="0.8*" />

  •       <RowDefinition Height="0.1*" />

  •     </Grid.RowDefinitions>

  •     <Grid.ColumnDefinitions>

  •       <ColumnDefinition Width="0.05*" />

  •       <ColumnDefinition Width="0.95*" />

  •     </Grid.ColumnDefinitions>

  •     <BoxView Grid.ColumnSpan="2"

  •              Color="Teal" />

  •     <Label Grid.Column="1"

  •            Text="{TemplateBinding Parent.HeaderText}"

  •            TextColor="White"

  •            FontSize="18"

  •            VerticalOptions="Center" />

  •     <ContentPresenter Grid.Row="1"

  •                       Grid.ColumnSpan="2" />

  •     <BoxView Grid.Row="2"

  •              Grid.ColumnSpan="2"

  •              Color="Teal" />

  •     <Label Grid.Row="2"

  •            Grid.Column="1"

  •            Text="{TemplateBinding Parent.FooterText}"

  •            TextColor="White"

  •            FontSize="18"

  •            VerticalOptions="Center" />

  •   </Grid>

  • </ControlTemplate>

在此代碼中,我們將兩個Label控件的Text屬性實(shí)現(xiàn)了模板綁定功能,在上文中我們提到了屬性使用模板綁定將其綁定到擁有ControlTemplate的目標(biāo)視圖的父級上的可綁定屬性上。但是,在我們的代碼中,模板綁定綁定到Parent.HeaderText和Parent.FooterText上,而不是HeaderText和FooterText上。這是因?yàn)樵诖舜a中,可綁定屬性是在目標(biāo)視圖的祖父級上定義的,而不是父級。

注意:模板綁定的源始終自動設(shè)置為擁有控件模板的目標(biāo)視圖的父級,在此項(xiàng)目中是ContentView實(shí)例。模板綁定使用Parent屬性返回ContentView實(shí)例的父元素,這是ContentPage實(shí)例。

以上是“Xamarin XAML語言中如何實(shí)現(xiàn)控件模板的模板綁定”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道!

當(dāng)前題目:XamarinXAML語言中如何實(shí)現(xiàn)控件模板的模板綁定-創(chuàng)新互聯(lián)
URL網(wǎng)址:http://www.yijiale78.com/article14/ccdpge.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、網(wǎng)站設(shè)計(jì)公司外貿(mào)網(wǎng)站建設(shè)、App開發(fā)、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)

廣告

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

小程序開發(fā)