I am trying to use an MvxDialogFragment to show a data bound dialog from an activity. My Dialog ViewModel is as follows:
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();
}
}
}
The MvxDialogFragment is coded as follows:
public class ContainerDialog : MvxDialogFragment<ContainerDialogViewModel>
{
public override Dialog OnCreateDialog(Bundle savedState)
{
base.EnsureBindingContextSet(savedState);
this.BindingInflate(Resource.Layout.ContainerDialog, null);
return base.OnCreateDialog(savedState);
}
}
In my activity, I am trying to figure out the simplest way to launch the dialog. Here is what I have tried:
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");
}
}
I'm pretty sure my method of creating the view model is unorthodox, but I don't know another way to do it. The biggest issue is that FragmentManager is cast to the wrong version. Show is looking for an Android.Support.V4.App.FragmentManager and the FragmentManager that is exposed is an Android.App.FragmentManager. I tried changing the MvxActivity to an MvxFragmentActivity, but this didn't seem to help. Can someone point me in the right direction?