Xamarin.Forms - ControlTemplate 不显示 ContentPresenter [英] Xamarin.Forms - ControlTemplate doesn't display ContentPresenter

查看:33
本文介绍了Xamarin.Forms - ControlTemplate 不显示 ContentPresenter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ControlTemplate 以便我可以在每个页面上都有一个页脚,但是每当我使用模板时,显示模板而页面内容消失.几乎就好像 ContentPresenter 不呈现页面内容,只呈现模板内容.我一直在使用

解决方案

在我的头撞墙一段时间后,似乎在我启动模拟器中的应用程序.

应用 ControlTemplate 后,预览器仅显示 ControlTemplate,而不显示页面内容.很可能是 Visual Studio 中的一个错误,所以做了一些挖掘:

比较老的Bugzilla,同样的问题

有同样问题的其他人

我使用的是 Visual Studio 7.7.4 和 Xamarin 5.2.1.15.猜猜我想预览我的页面时只需要关闭 ControlTemplate.

I'm trying to use a ControlTemplate so I can have a footer on every page, but whenever I use the template, only the template is shown and the page content disappears. It's almost as if the ContentPresenter isn't rendering the page content, only the template content. I have been using this official doc to get the template working, but with no avail.

Here's my template code:

<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>

And the page code:

<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>

As you can see from the output of this code, only the ContentTemplate is being displayed, and not the "Page Content" label (ContentPresenter content). How can I display page content as well as template content?

解决方案

After banging my head against the wall for a while, it seems that the page content is actually being rendered once I start up the app in the simulator.

The previewer only displays the ControlTemplate, and not the page content, once a ControlTemplate has been applied. Most likely a bug in Visual Studio, so did some digging:

Relatively old Bugzilla, same problem

Someone else with the same problem

I'm using Visual Studio 7.7.4 and Xamarin 5.2.1.15. Guess I'll just have to take the ControlTemplate off whenever I want to preview my page.

这篇关于Xamarin.Forms - ControlTemplate 不显示 ContentPresenter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆