I'm still getting used to Xamarin Forms, so I have the following control called 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>
In my view:
<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>
So what's happening is that When the ContentView control shows, only the Label (with the text -- TEST TITLE -- is displayed, but not the ListView).
I've also tried replacing the ContentPreseter with a ContentView, but same result: my ListView doesn't not show. And I made sure that data does in fact exist in the ItemsSource of the ListView (set in code-behind).
Is my ContentView setup wrong??
TemplateBinding can only be used to bind from inside a control-template. In order for your binding to work - you can use ReferenceExtension to refer to parent control.
For ex, update your binding as following:
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With