Digging into MAUI Blazor and trying to see if its possible to call methods of the host page of the BlazorWebView. (Like MainPage.xaml.cs)
We can call App.Current.MainPage.DisplayAlert
so would it be possible to call something like App.Current.MainPage.MyMethod
?
however creating a public method in the MainPage does not expose it like highlighted above.
I understand I can create a class and reference, but in this particular use case scenario I need to see if the above is possible. So far have found no documentation on it.
App.Current.MainPage
to the appropriate type of YOUR app in order to access any public methods – CalentureApp.Current.MainPage
is just aPage
, you will need to cast it to the subclass that contains the methods you want to use. – CalentureMyApp
and pageMyPage
, if you were writing within the Maui code itself, the syntax would be((MyPage)App.Current.MainPage).MyMethod
or the full path((MyApp.MyPage)App.Current.MainPage).MyMethod
. But I don't know in Blazor how you get at the app namespace. Must be some way to "bridge" to host code. OR might need to define some Interface or some communication mechanism. – Pandanus"bridge" to host code
Seeing thatApp.Current.MainPage.DisplayAlert
works and reaches the host page. I've tried what you recommended already with no luck. – Munson