Christine
Christine

Reputation: 629

(Xamarin Forms) How do I get the BasePageType of my Page

I have a pages called FirstMainPage and SecondMainPage which both inherit from MasterDetailPage. In my App.cs I do a MainPage.GetType it will return the Type FirstMainPage or SecondMainPage (or something else). How do I get the BasePageType so it returns MasterDetailPage if the page inherits from MasterDetailPage?

I want to be able to cast the MainPage to MasterDetailPage so I can access the MasterDetailPage.Master if it is a MasterDetailPage.

Upvotes: 0

Views: 68

Answers (1)

SushiHangover
SushiHangover

Reputation: 74144

You can do a simple is test on your Page to determine is it is a master-detail:

if (MainPage is MasterDetailPage) 
{
  var master = (MainPage as MasterDetailPage).Master;
}

Ref: is (C# Reference)

Upvotes: 1

Related Questions