This is a migrated thread and some comments may be shown as answers.

Centering Popup against the entire app window when defined in a ContentView?

1 Answer 72 Views
Popup
This is a migrated thread and some comments may be shown as answers.
jeljeljel
Top achievements
Rank 2
jeljeljel asked on 09 Jul 2019, 04:21 PM

I have a sample Xamarin Forms app (source located on GitHub here) where I need the dialog that pops when you click the button to center itself on the screen.  Instead it is centering in its parent.

I read you can center a Popup by attaching it to the page level.  And that works fine.  But the BindingContext for the popup can't be set in this way.

Our app uses a ContentPage that is comprised of a bunch of ContentViews.  And the ContentViews are the things that define the various popup dialogs (not the ContentPage).  Furthermore, the BindingContext is set at the ContentView level.  You can see an example of this in the code example I provided in the repo.

The repo defines a MainPage.xaml which hosts a ParentView which hosts a PopupView.  It should be easy to follow the structure.

How can this sample be changed to show the dialog in the center of the screen?

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 10 Jul 2019, 11:57 AM
Hi John,

Thank you for sending the sample - it helped me understand the exact scenario you have.

In such cases you would need to create the Popup control with code, not in XAML, in order to avoid attaching it to the ContentView element. You could still define the content in XAML through a ControlTemplate which then can be set to the Content property of the Popup instance.

I have modified the sample app to show you how this would work. Please note that I am using Xamarin.Forms MessagingCenter to send a notification when the popup should be open. When created in this way, the popup takes the page as its placement target element and is properly centered.  

Please download the attachment and give it a try.

You could also check the RadPopup examples in our QSF application which also demonstrate the approach.

Let me know if you have any additional questions on this.
 
Regards,
Yana
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Popup
Asked by
jeljeljel
Top achievements
Rank 2
Answers by
Yana
Telerik team
Share this question
or