android - Xamarin.Forms - ControlTemplate 不显示 ContentPresenter
问题描述
我正在尝试使用 ControlTemplate,这样我就可以在每个页面上都有一个页脚,但是每当我使用模板时,只会显示模板并且页面内容会消失。就好像ContentPresenter
没有渲染页面内容,只有模板内容。我一直在使用这个官方文档来使模板正常工作,但无济于事。
这是我的模板代码:
<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 内容)。如何显示页面内容以及模板内容?
解决方案
在我的头撞墙一段时间后,一旦我在模拟器中启动应用程序,似乎页面内容实际上正在呈现。
应用ControlTemplate 后,预览器仅显示 ControlTemplate,而不显示页面内容。很可能是 Visual Studio 中的一个错误,因此进行了一些挖掘:
我正在使用 Visual Studio 7.7.4 和 Xamarin 5.2.1.15。猜猜我只需要在我想预览我的页面时关闭 ControlTemplate。
推荐阅读
- scala - 如何在 Scala 中提供静态 HTML 文件?
- json - Django模板如何使用标签和模板过滤器从json dict中获取数据
- c# - 正确的值不是来自 web.config 文件
- javascript - 如何修复“CheckBoxData []类型上不存在属性'值'”?
- spring-boot - 如何为lamda表达式编写junits
- python-3.x - 使用 nunique 标记数据框中的重复值但出现错误
- amazon-web-services - 为什么 AWS Glue 工作有时似乎在工作中使用较少的执行者
- ansible - Ansible - 从清单主机名定义的变量列表中的项目列表
- c++ - 英特尔 C++ 编译器 (19.0) 现在是否只使用 Clang 前端(即已经放弃 EDG)?
- python - Python中奇怪的字符串格式