Xamarin XAML語言教程構(gòu)建ControlTemplate控件模板 (二)
(2)打開MainPage.xaml文件,編寫代碼,將構(gòu)建的控件模板應(yīng)用于ContentView中。代碼如下:

在此代碼中TealTemplate控件模板通過使用StaticResource標(biāo)記擴(kuò)展分配給ContentView.ControlTemplate屬性。ContentView.Content屬性設(shè)置為StackLayout,用于定義要在ContentPage上顯示的內(nèi)容。此內(nèi)容將由TealTemplate中包含的ContentPresenter顯示。