2
所以我有一个片段没有显示在MvxCachingFragmentCompatActivity
内部的问题。Mvvmcross:framelayout在活动后不显示片段
我用它来找到问题的模式如下:
- 注册一个活动。
- 导航到扩展MvxCachingFragmentCompatActivity
- 负载使用
await _navigationService.Navigate<[TheFragmentViewModel]>();
- 片段装载的片段另一个活动的调用,但它并没有显示任何东西。
片段声明:
[MvxFragment(typeof(MainViewModel), Resource.Id.content_frame, true)]
[Register(nameof(FirstFragment))]
public class FirstFragment : MvxFragment<FirstViewModel>
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
var view = this.BindingInflate(Resource.Layout.FirstView, container, false);
return view;
}
}
主要活动:(没有什么特别的,我认为)
[Activity(Label = "Fragment View")]
public class MainActivity : MvxCachingFragmentCompatActivity<MainViewModel>
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.MainView);
}
}
麦Ñ视图模型
public class MainViewModel : MvxViewModel
{
private readonly IMvxNavigationService _navigationService;
public MainViewModel(IMvxNavigationService navigationService)
{
_navigationService = navigationService;
Init();
}
public async void Init()
{
await _navigationService.Navigate<FirstViewModel>();
}
}
主要业务布局:(非常简单的布局)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
我还添加在github样品:Github link。
我还加了a bug report on the Mvvmcross github,但我不确定这是我的一部分还是他们的错误?
我开始对所有事情都没有足够的理解,对于你的人来说,我仍然在学习一点:) – kevingoos