Beispiel #1
0
        public void AddViewMapping <TViewModel, TPlatformView>() where TViewModel : IBaseViewModel where TPlatformView : IPlatformView
        {
            if (ViewMapperDictionary == null)
            {
                Init();
            }

            if (ViewMapperDictionary.ContainsKey(typeof(TViewModel)))
            {
                throw new System.Exception($"The viewmodel '{typeof(TViewModel).ToString()}' does already exist in view mapper!");
            }

            ViewMapperDictionary.Add(typeof(TViewModel), typeof(TPlatformView));
        }
Beispiel #2
0
        public void NavigateToSubView(Type viewModelType, IPayload parameter = null, Action <Guid> callback = null, bool clearHistory = false)
        {
            if (SubViewContainer == null)
            {
                throw new Exception("SubViewController and SubViewContainer must be set!");
            }

            if (ViewMapperDictionary.TryGetValue(viewModelType, out Type viewControllerType) == false)
            {
                throw new Exception($"The viewmodel '{viewModelType.ToString()}' does not exist in view mapper!");
            }

            // Add
            var subView = InstantiateViewController(viewControllerType);

            if (subView == null)
            {
                System.Diagnostics.Debug.WriteLine($"AppNavigation.NavigateToSubView: The ViewController for VM '{viewModelType.ToString()}' could not be loaded!");
                return;
            }

            if (subView is IViewControllerBase frameworkVc)
            {
                // Handle payload parameter
                if (parameter != null)
                {
                    // Set payload id
                    frameworkVc.SetPayload(parameter);
                }

                // Handle callback
                if (callback != null)
                {
                    frameworkVc.SetCallback(callback);
                }
            }

            InflateSubView(subView);
        }