[英]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.如果 Main Project 包含承载 FrameLayout 的 MainActivity。
How exactly would one use the MvxNavigationService to navigate to a fragment using the MvxFragmentPresentationAttribute, when that attribute requires two vital pieces of information:当该属性需要两个重要信息时,如何使用 MvxNavigationService 导航到使用 MvxFragmentPresentationAttribute 的片段:
Is there anyway to accomplish this?有没有办法做到这一点?
Thanks谢谢
Your fragment class would look like this.您的片段 class 看起来像这样。
[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.这里 MainViewModel 与托管此片段的 MainActivity 相关联。
To launch this fragment.启动这个片段。
Suppose you want to go to CardsBaseView from MyView;假设你想 go 从 MyView 到 CardsBaseView;
Your MyViewModel should look like the below.您的 MyViewModel 应如下所示。
public class MyViewModel : MvxViewModel
{
private readonly IMvxNavigationService _navigationService;
public MyViewModel(IMvxNavigationService navigationService)
{
_navigationService = navigationService;
}
void NavigateToCardsView(){
_navigationService.Navigate<CardsBaseViewModel>();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.