Exemplo n.º 1
0
        /// <summary>
        /// Creates a View of the given type.
        /// </summary>
        public IView CreateViewFor(Type viewModelType)
        {
            string viewName = ViewViewModelHelper.ViewNameFromViewModel(viewModelType);
            Type   pageType = _availableViewTypes
                              .FirstOrDefault(t => t.Name == viewName);

            var view = Activator.CreateInstance(pageType) as IView;

            if (view == null)
            {
                throw new MvvmNanoFormsPresenterException($"{viewName} could not be found. Does it implement IView?");
            }

            if (!(view is Page))
            {
                throw new MvvmNanoFormsPresenterException($"{viewName} is not a Xamarin.Forms Page.");
            }

            return(view);
        }