android - Xamarin.Forms - ControlTemplate 不显示 ContentPresenter

标签 android ios xamarin xamarin.forms

我正在尝试使用 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 内容)。如何同时显示页面内容和模板内容?

page output

最佳答案

在我用头撞墙一段时间后,一旦我在模拟器中启动应用程序,页面内容似乎就会被渲染。

应用 ControlTemplate 后,预览器仅显示 ControlTemplate,而不显示页面内容。很可能是 Visual Studio 中的错误,因此进行了一些挖掘:

Relatively old Bugzilla, same problem

Someone else with the same problem

我使用的是 Visual Studio 7.7.4 和 Xamarin 5.2.1.15。我想只要我想预览页面,我就必须关闭 ControlTemplate。

关于android - Xamarin.Forms - ControlTemplate 不显示 ContentPresenter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54706933/

相关文章:

java - 务实地检测 MIUI/小米设备中软导航栏的可用性?

iOS,点击进入文本 block 后的 Action

ios - MKAnnotationView pin.image 显示的图像不正确

c# - 从 Xamarin.iOS 中的泛型基类继承时出错

ios - 从 Xamarin.iOS 中的 TableView 单元格以编程方式推送 segue

java - Android,EditText 在按完成后不更新变量

android - 图库中的 TextView

ios - 设置一些气泡的最小宽度

android - 在 GridView 适配器 GetView 方法中使用异步方法

android - Flutter-ListView 溢出