Xaml Xamarin表单-我的内容演示者赢得';我不能展示它的内容

Xaml Xamarin表单-我的内容演示者赢得';我不能展示它的内容,xaml,xamarin,xamarin.forms,Xaml,Xamarin,Xamarin.forms,我仍然习惯于Xamarin表单,因此我有一个名为PopupFrame的控件: PopupFrame.cs [XamlCompilation(XamlCompilationOptions.Compile)] public partial class PopupFrame : ContentView { public static readonly BindableProperty PopupContentProperty = BindableProperty.Create(

我仍然习惯于Xamarin表单,因此我有一个名为PopupFrame的控件:

PopupFrame.cs

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class PopupFrame : ContentView
{
    public static readonly BindableProperty PopupContentProperty =
        BindableProperty.Create(nameof(PopupContent), typeof(View), typeof(PopupFrame));

    public View PopupContent
    {
        get { return (View)GetValue(PopupContentProperty); }
        set { SetValue(PopupContentProperty, value); }
    }

    public PopupFrame()
    {
        InitializeComponent();
    }
}
PopupFrame.xaml

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="TestApp.Core.Controls.PopupFrame">
    <Frame>
        <StackLayout>
            <Label Text="--- TEST TITLE ---" />

            <ContentPresenter Content="{TemplateBinding PopupContent}" />
        </StackLayout>
    </Frame>
</ContentView>

在我看来:

<popCtl:PopupFrame HorizontalOptions="Center"
                   VerticalOptions="Center">
    <popCtl:PopupFrame.PopupContent>
        <ListView x:Name="ListUsers">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <ViewCell.View>
                            <Label Text="{Binding Name}"
                                   HorizontalOptions="CenterAndExpand"
                                   VerticalOptions="Center" />
                        </ViewCell.View>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
        </popCtl:PopupFrame.PopupContent>
</popCtl:PopupFrame>

因此,当ContentView控件显示时,只显示标签(带有文本--TEST TITLE--但不显示ListView)

我还尝试用ContentView替换ContentPreseter,但结果相同:我的ListView不显示。我确保数据确实存在于ListView的ItemsSource中(在代码隐藏中设置)

我的ContentView设置是否错误???

只能用于从控件模板内部绑定。为了使绑定正常工作,可以使用引用父控件

对于ex,请按以下方式更新绑定:

<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="TestApp.Core.Controls.PopupFrame"
             x:Name="_parent">
    <Frame>
        <StackLayout>
            <Label Text="--- TEST TITLE ---" />

            <ContentPresenter 
                 Content="{Binding Path=PopupContent, Source={x:Reference _parent}}" />
        </StackLayout>
    </Frame>
</ContentView>

Wow,x:Reference对我来说绝对是新鲜事。这可以解释为什么XF中缺少RelativeSource。谢谢,工作很有魅力!