/// <summary> /// Given a view model attempts to close the fragment associated with it. If the fragment /// associated is currently being displayed in the fragment host then the backstack /// is popped. /// </summary> /// <param name="viewModel"></param> /// <returns></returns> public bool Close(IMvxViewModel viewModel) { var fragmentTypeToClose = SupportedFragmentViewModels[viewModel.GetType()]; if (CurrentFragment != null && CurrentFragment.GetType() == fragmentTypeToClose) { FragmentManager.PopBackStackImmediate(); this.FragmentChanged(); return(true); } else { return(false); } }
/// <summary> /// Remove all fragments from the back stack up to, but not including the specified view. /// </summary> /// <remarks> /// If the specified view is not found then all fragments will be removed up to, but not including, the initial view. /// </remarks> public void CloseUpToView(Type viewModelType) { var targetFragmentType = SupportedFragmentViewModels[viewModelType]; var backStackEntryCount = FragmentManager.BackStackEntryCount; for (var i = 0; i < backStackEntryCount; i++) { if (CurrentFragment.GetType() == targetFragmentType) { break; } FragmentManager.PopBackStackImmediate(); } this.FragmentChanged(); }
/// <summary> /// This method does the actual loading of the fragment depending on current step. /// </summary> private void LoadFragment() { if (_currentFragmentType == null) { throw new InvalidOperationException("Cannot load fragment if there is CurrentFragmentType == null."); } // load the fragment needed CurrentFragment = Activator.CreateInstance(_currentFragmentType) as WizardStepFragment; if (CurrentFragment == null) { throw new Exception("Fragments used for steps in the wizard must inherit WizardStepFragment. Yours does not."); } if (!StepsHistory.ContainsKey(_currentStep)) { StepsHistory.Add(_currentStep, CurrentFragment.GetType()); } else { StepsHistory[_currentStep] = CurrentFragment.GetType(); } if (!_serializedData.IsBlank()) { RunOnUiThread(() => { CurrentFragment.SetData(_serializedData); }); } // load the actual fragment needed if (!_isHidden) { SupportFragmentManager.BeginTransaction() .Replace(Resource.Id.frameContent, CurrentFragment, CurrentFragment.FragmentTag) .Commit(); } this.SetButtonTitles(); _fragmentButtons.SelectStep(_currentStep); HideKeyboard(true); }