【发布时间】:2019-02-15 10:08:25
【问题描述】:
我正在尝试使用 ControlTemplate,以便在每个页面上都有一个页脚,但是每当我使用模板时,仅显示模板并且页面内容消失。就好像ContentPresenter 不呈现页面内容,只呈现模板内容。我一直在使用this official doc 来使模板正常工作,但无济于事。
这是我的模板代码:
<Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="TestApp.App">
<Application.Resources>
<ResourceDictionary>
<ControlTemplate x:Key="MainFooter">
<Grid>
<ContentPresenter/>
<Label Text="Template footer" FontSize="24"/>
</Grid>
</ControlTemplate>
</ResourceDictionary>
</Application.Resources>
</Application>
以及页面代码:
<ContentPage Title="Test" xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestApp.Login">
<ContentView ControlTemplate="{StaticResource MainFooter}" Padding="0, 20, 0, 0">
<StackLayout VerticalOptions="CenterAndExpand">
<Label Text="Page content" HorizontalOptions="Center"/>
</StackLayout>
</ContentView>
</ContentPage>
从这段代码的输出可以看出,只有 ContentTemplate 被显示,而不是“页面内容”标签(ContentPresenter 内容)。如何显示页面内容和模板内容?
【问题讨论】:
标签: android ios xamarin xamarin.forms