C# MvvmCross Android:屏幕旋转后绑定丢失

C# MvvmCross Android:屏幕旋转后绑定丢失,c#,android,mvvmcross,C#,Android,Mvvmcross,我的装订工作很好,但在屏幕旋转后我松开了装订 在OnCreateView中,我尝试按标记还原片段,如果FindFragmentByTag返回null,我将创建如下新实例: protected virtual TFragmentType PutFragment<TFragmentType, TViewModelType>(int oldId, TViewModelType vm) where TFragmentType : FragmentBase, new()

我的装订工作很好,但在屏幕旋转后我松开了装订

在OnCreateView中,我尝试按标记还原片段,如果FindFragmentByTag返回null,我将创建如下新实例:

protected virtual TFragmentType PutFragment<TFragmentType, TViewModelType>(int oldId, TViewModelType vm)
        where TFragmentType : FragmentBase, new()
        where TViewModelType : IViewModelBase
    {
        var tag = typeof(TFragmentType).FullName;
        var fragment = SupportFragmentManager.FindFragmentByTag(tag) as TFragmentType;
        if (fragment == null)
        {
            fragment = new TFragmentType() { ViewModel = vm };
            SupportFragmentManager.BeginTransaction().Replace(oldId, fragment, tag).Commit();
            fragment.RetainInstance = true;
        }
        return fragment;
    }
受保护的虚拟TfFragmentType PutFragment(int-oldId,TViewModelType-vm)
其中TfFragmentType:FragmentBase,new()
其中TViewModelType:IViewModelBase
{
var tag=typeof(TFragmentType).FullName;
var fragment=SupportFragmentManager.FindFragmentByTag(标记)作为TFragmentType;
if(片段==null)
{
fragment=new TFragmentType(){ViewModel=vm};
SupportFragmentManager.BeginTransaction().Replace(oldId、fragment、tag).Commit();
fragment.RetainInstance=true;
}
返回片段;
}
当GetFragmentByTag返回一些东西时(在我的例子中,是在sctreen旋转之后),就会出现问题

屏幕截图

旋转前:

之后:


提前谢谢。

谢谢大家,我在“活动”属性中指定了“配置更改”

[Activity (ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.KeyboardHidden)]

它现在工作正常(ConfigurationChanges=ConfigChanges.Orientation)就足够了

请看下面的帖子,这对我来说很有效,肖恩的建议是+1。这里的问题可能不是缺少绑定,而是片段丢失了它的DataContext/ViewModel,因此需要将它返回一个新的绑定。编辑问题以包含为片段设置ViewModel的代码可能会有所帮助