Senthilkumar
Senthilkumar

Reputation: 63

How to get the view instance from IMvxAndroidViewPresenter in xamarin android using mvvmcross

How to get the view from viewpresenter.

var viewpresenter = Mvx.Resolve<IMvxAndroidViewPresenter>();
viewpresenter.Show(new MvxViewModelRequest(typeof(IVP), null, null, null));

Thanks.

Upvotes: 0

Views: 443

Answers (1)

fmaccaroni
fmaccaroni

Reputation: 3916

I'm not sure what you want to do but from your code you want to perform a navigation. In such case you should use the Navigation service (requires Mvx >= 5, otherwise use ShowViewModel from your ViewModel/MvxNavigatingObject) and use it like this:

var navigationService = Mvx.Resolve<IMvxNavigationService>();
await navigationService.Navigate<MyViewModel>();

If you want a custom navigation just call

await navigationService.ChangePresentation(new MyCustomPresentationHint());

and in your custom presenter override ChangePresentation(MvxPresentationHint hint) to add your custom presentation logic.

The Presenter is not there to resolve it and use it directly but through the navigation service.

Here is the source code of the Android Presenter from where you can see that you cannot get the current view directly. If you would like to know which is your current Activity you could use

var currentActivity = Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity;

HIH

Upvotes: 1

Related Questions