简体   繁体   English

处理class库时如何使用MVVMCross将Fragment组成一个Activity

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

If you have the following project structure:如果您有以下项目结构:

  • Main Project - Android Host app主要项目 - Android 主机应用程序
  • Component A - Android Class Library组件 A - Android Class 库
  • Component B - Android Class Library组件 B - Android Class 库

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 的片段:

  • Type of the Host viewmodel主机视图模型的类型
  • Android Resource Id of the FrameLayout. Android FrameLayout 的资源 ID。

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.

相关问题 如何在已经扩展了另一个类的活动中使用片段? - How to use fragments in an activity which already extends another class? 使用片段时使用片段活动吗? - Use Fragment Activity when we use Fragments? 如何在撰写中使用活动作为导航器 - How to use activity as a navigator in compose 重新启动活动 - 将两个片段处理到一个容器中 - Restart activity - dealing with two fragments into a container Mvvmcross片段 - Mvvmcross fragments 如何使用viewpager在不同片段中使用活动组件 - How to use an activity component in different fragments with viewpager 在处理滚动片段和非滚动片段时,是否应将CoordinatorLayout放置在Activity或Fragment中? - Should the CoordinatorLayout be placed in the Activity or the Fragment when dealing with both scrolling and non-scrolling fragments? Jetpack 导航:在片段之间导航时,如何使用与启动新活动时相同的动画? - Jetpack Navigation: When navigating between fragments, how can I use the same animation as when launching a new activity? 转换活动以使用片段? - Converting Activity to use Fragments? 如何以及何时在应用程序中使用Fragments? - How and when to use Fragments in applications?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM