我正在尝试使用MvxDialogFragment在活动中展示一个数据绑定的对话框。我的对话框视图模型如下:
public class ContainerDialogViewModel : MvxViewModel
{
public string ShipperName;
public void Init(string Name)
{
ShipperName = Name;
LoadData();
}
public void LoadData()
{
Survey = SurveyDataSource.CurrSurvey;
}
private ShipmentSurvey _Survey;
public ShipmentSurvey Survey
{
get
{
return _Survey;
}
set
{
_Survey = value;
RaisePropertyChanged(() => Survey);
RaisePropertyChanged(() => Containers);
}
}
public List<ShipmentSurveyContainer> Containers
{
get
{
if (Survey == null)
return new List<ShipmentSurveyContainer>();
else
return Survey.SurveyContainers.ToList();
}
}
}
MvxDialogFragment的代码如下:
public class ContainerDialog : MvxDialogFragment<ContainerDialogViewModel>
{
public override Dialog OnCreateDialog(Bundle savedState)
{
base.EnsureBindingContextSet(savedState);
this.BindingInflate(Resource.Layout.ContainerDialog, null);
return base.OnCreateDialog(savedState);
}
}
在我的活动中,我正在尝试找到启动对话框的最简单方法。以下是我尝试过的方法:
public class SurveyView : MvxActivity
{
public void ShowContainerDialog()
{
ContainerDialogViewModel vm = new ViewModels.ContainerDialogViewModel();
vm.Init("Test Name");
var dialogFragment = new ContainerDialog()
{
DataContext = vm
};
dialogFragment.Show(FragmentManager, "Containers");
}
}
我很确定我的创建视图模型的方法是不正规的,但我不知道其他的方法。最大的问题是FragmentManager被转换成了错误的版本。Show正在寻找一个Android.Support.V4.App.FragmentManager,而暴露出来的FragmentManager是一个Android.App.FragmentManager。我尝试将MvxActivity更改为MvxFragmentActivity,但这似乎没有帮助。有人可以指引我正确的方向吗?