ShowPopupAsync inside a contentview in .net MAUI

650 Views Asked by At

I created two pages in maui app: a ContentView and a ContentPage. Inside the ContentView component, I need to call a popup and show some contents in the page. In my current Implementation on ContentView, I declared a bindable property of type ContentPage for the reason of using the instance to call the ShowPopupAsync method.

Bindable Property in the nxi-lookup.xaml.cs

    public BindableProperty ParentPageProperty =
    BindableProperty.Create(
    nameof(Page),
    typeof(ContentPage),
    typeof(nxi_lookup),
    defaultValue: null,
    defaultBindingMode: BindingMode.OneWay);

my contentpage xaml

 <custom:nxi_lookup Page="{Binding Page,Source={x:Reference Production}}" Margin="0,0,10,10" WidthValue="10"  LabelText="Lookup 1" IsRequired="True"/>

Actual usage for popup inside the contentview

     if (Page != null)
        {
            var popup = new nxi_popup();
            var content = new nxi_lookupcontent();
            popup.Content = content;
            await Page.ShowPopupAsync(popup);
        }

Error XFC0009 No property, BindableProperty, or event found for "Page", or mismatching type.

I tried changing the type of the bindable property but does not work. I expected to bind the contentpage to my property in content view.

Is there any way to properly implement popup in a contentview?

1

There are 1 best solutions below

2
Liyun Zhang - MSFT On

The offical document said:

The naming convention for bindable properties is that the bindable property identifier must match the property name specified in the Create method, with "Property" appended to it.

So you can change the code public BindableProperty ParentPageProperty = to public BindableProperty PageProperty =.

In addition, did you create accessors for the bindable property?