wpa
wpa

Reputation: 220

How to use MVVMCross to compose fragments into an Activity when dealing with class libraries

If you have the following project structure:

If Main Project contains the MainActivity that hosts the FrameLayout.

How exactly would one use the MvxNavigationService to navigate to a fragment using the MvxFragmentPresentationAttribute, when that attribute requires two vital pieces of information:

Is there anyway to accomplish this?

Thanks

Upvotes: 0

Views: 180

Answers (1)

Saket Kumar
Saket Kumar

Reputation: 1197

Your fragment class would look like this.

[MvxFragmentPresentation(typeof(MainViewModel), Resource.Id.frameLayout, AddToBackStack = true)]
[Register("mynamespace.CardsBaseView")]
public class CardsBaseView : MvxFragment<CardsBaseViewModel> {
}

Here MainViewModel is associated with MainActivity which is hosting this frag.

To launch this fragment.

Suppose you want to go to CardsBaseView from MyView;

Your MyViewModel should look like the below.

public class MyViewModel : MvxViewModel
{
    private readonly IMvxNavigationService _navigationService;

    public MyViewModel(IMvxNavigationService navigationService)
    {
        _navigationService = navigationService;
    }
void NavigateToCardsView(){
_navigationService.Navigate<CardsBaseViewModel>(); 
}

Upvotes: 1

Related Questions