How can we change the PlacementTarget for popup in the codebehind?

1 Answer 485 Views
Popup
Scofield
Top achievements
Rank 2
Iron
Iron
Scofield asked on 07 Apr 2022, 03:23 AM

If you create the Popup with code, you have to explicitly set the PlacementTarget property. Any example?

When the Popup is declared in XAML and you want to center it, attach it to the Page element and set its Placement property to "Center". How to attach it to Page? 

1 Answer, 1 is accepted

Sort by
0
Accepted
Lance | Manager Technical Support
Telerik team
answered on 07 Apr 2022, 01:12 PM

Hi Scofield,

If your ContentPage has an x:Name, then you can use that name for the PlacementTarget:

popup.PlacementTarget = MyPage;

Otherwise, you can use 'this' for the page object, let me explain.

The 'this' keyword means the object that the code's current class. So, if you're writing code in the code -behind of a ContentPage, you can use 'this' for the PlacementTarget.

Regards,
Lance | Manager Technical Support
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Scofield
Top achievements
Rank 2
Iron
Iron
commented on 07 Apr 2022, 02:52 PM

Thanks for your feedback and I did the same code in my MianPage of my .Net Maui project, but I got the NullReferenceException, any advice on it?
Lance | Manager Technical Support
Telerik team
commented on 07 Apr 2022, 05:04 PM

Ah, I am also getting an exception, my apologies for missing this earlier. I am opening a Bug Report on your behalf  so that I can involve the development team to investigate this.

Go here to see the item => https://feedback.telerik.com/maui/1560818, someone form the MAUI team will follow up once they've had a chance to review it.

Unfortunately, I have not yet been able to find a workaround. I will keep tinkering, if I am eventually successful, I'll let you know. 

 

Scofield
Top achievements
Rank 2
Iron
Iron
commented on 11 Apr 2022, 07:29 AM | edited

Hi Lance, I found some workaround for this one, it can work well if we put the teletikUI popup code into other method instead of the structure method in MainPage.
Lance | Manager Technical Support
Telerik team
commented on 11 Apr 2022, 12:35 PM

Correct, anywhere except the constructor of the first page in the project, will be fine. The underlying problem is due to App.Current.Main is not ready by the time we attempt to attach the popup. That's the source of the NullReferenceException you're seeing. We have already fixed this internally and it will be available in the next preview update (0.7.0)
Tags
Popup
Asked by
Scofield
Top achievements
Rank 2
Iron
Iron
Answers by
Lance | Manager Technical Support
Telerik team
Share this question
or