简体   繁体   中英

Using method from ContentPage after it is created as a NavigationPage

I am having trouble accesing a method from my ContentPage. I have a mainPage in wich i create a NavigationPage with a ContentPage as a Parameter. The ContentPage just holds a WebView. (BrowserPage is the ContentPage)

public static NavigationPage browserPage;  
browserPage = new NavigationPage(new BrowserPage());

How can i acces propertys and methods from the ContentPage?

browserPage.someMethodFromBrowserPage(someParameter);

I know that this wont work, i can only call methods from NavigationPage that way.

((BrowserPage)browserPage).someMethod(someParameter);

This is also not working, its says NavigationPage cannot be converted to BrowserPage :( .

So, how do i cast accordingly so i can use the methods that i created inside the BrowserPage?

The NavigationPage and the BrowserPage it contains are two independent things. You can easily keep a ref to both:

public static BrowserPage browserPage = new BrowserPage();
var navPage = new NavigationPage(browserPage);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM