Xamarin XAML语言教程构建ControlTemplate控件模板 (二)
2017-07-13 00:00
591 查看
摘要: Xamarin XAML语言教程构建ControlTemplate控件模板 (二)
Xamarin XAML语言教程构建ControlTemplate控件模板 (二)
(2)打开MainPage.xaml文件,编写代码,将构建的控件模板应用于ContentView中。代码如下:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ControlTemplateDemo"
x:Class="ControlTemplateDemo.MainPage">
<ContentView x:Name="contentView"
Padding="0,20,0,0"
ControlTemplate="{StaticResource TealTemplate}">
<StackLayout Spacing="20"
VerticalOptions="Center">
<Label Text="If a jewel falls into the mire, it remains as precious as before; and though dust should ascend to heaven, its former worthlessness will not be altered."
FontSize="20"
FontAttributes="Bold"/>
<Button Text="改变主题"
Clicked="OnButtonClicked" />
</StackLayout>
</ContentView>
</ContentPage>
在此代码中TealTemplate控件模板通过使用StaticResource标记扩展分配给ContentView.ControlTemplate属性。ContentView.Content属性设置为StackLayout,用于定义要在ContentPage上显示的内容。 此内容将由TealTemplate中包含的ContentPresenter显示。
Xamarin XAML语言教程构建ControlTemplate控件模板 (二)
(2)打开MainPage.xaml文件,编写代码,将构建的控件模板应用于ContentView中。代码如下:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ControlTemplateDemo"
x:Class="ControlTemplateDemo.MainPage">
<ContentView x:Name="contentView"
Padding="0,20,0,0"
ControlTemplate="{StaticResource TealTemplate}">
<StackLayout Spacing="20"
VerticalOptions="Center">
<Label Text="If a jewel falls into the mire, it remains as precious as before; and though dust should ascend to heaven, its former worthlessness will not be altered."
FontSize="20"
FontAttributes="Bold"/>
<Button Text="改变主题"
Clicked="OnButtonClicked" />
</StackLayout>
</ContentView>
</ContentPage>
在此代码中TealTemplate控件模板通过使用StaticResource标记扩展分配给ContentView.ControlTemplate属性。ContentView.Content属性设置为StackLayout,用于定义要在ContentPage上显示的内容。 此内容将由TealTemplate中包含的ContentPresenter显示。
相关文章推荐
- Xamarin XAML语言教程构建ControlTemplate控件模板
- Xamarin XAML语言教程构建ControlTemplate控件模板 (四)
- Xamarin XAML语言教程构建ControlTemplate控件模板 (二)
- Xamarin XAML语言教程构建ControlTemplate控件模板 (二)
- Xamarin XAML语言教程构建ControlTemplate控件模板 (四)
- Xamarin XAML语言教程构建ControlTemplate控件模板 (三)
- Xamarin XAML语言教程构建ControlTemplate控件模板 (三)
- Xamarin XAML语言教程构建ControlTemplate控件模板 (三)
- Xamarin XAML语言教程构建ControlTemplate控件模板
- Xamarin XAML语言教程构建ControlTemplate控件模板 (四)
- Xamarin XAML语言教程控件模板的模板绑定
- Xamarin XAML语言教程控件模板的模板绑定
- Xamarin XAML语言教程控件模板的模板绑定
- Xamarin XAML语言教程Xamarin.Forms中构建进度条
- Xamarin XAML语言教程模板视图TemplatedView(二)
- Xamarin XAML语言教程模板视图TemplatedView(一)
- Xamarin XAML语言教程构建ControlTemplate控件模板
- Xamarin XAML语言教程模板页面TemplatedPage
- Xamarin XAML语言教程构建进度条ProgressBar
- Xamarin XAML语言教程构建进度条ProgressBar