コード例 #1
0
ファイル: InfoViewModel.cs プロジェクト: SamirHafez/Nutrition
        protected override void InitFromBundle(IMvxBundle parameters)
        {
            var nutritionTable = parameters.Read <NutritionTable>();

            Score = NutritionService.GetScore(nutritionTable);

            Balance = Mvx.Create <BalanceViewModel>();
            Balance.Update(nutritionTable);
        }
コード例 #2
0
        /// <summary>
        /// Creates a new instance of <typeparamref name="TVM" /> assuming it is already registered.
        /// </summary>
        /// <typeparam name="TVM">The type of the vm.</typeparam>
        /// <typeparam name="TV">The type of the average.</typeparam>
        /// <returns>
        ///   <typeparamref name="TVM" />var viewModel = Mvx.Create<TVM>();
        /// </returns>
        /// <exception cref="System.Exception"> If types are not registered.
        /// </exception>
        public TVM Create <TVM, TV>()
            where TVM : class, IViewModel <TV>, IMvxViewModel
            where TV : class, IView <TVM>

        {
            if (!Mvx.CanResolve <TVM>())
            {
                throw new Exception(string.Format("MyViewModel Type {0} is not registered. Please register it before calling this method.", typeof(TVM)));
            }

            if (!Mvx.CanResolve <TV>())
            {
                throw new Exception(string.Format("MyView Type {0} is not registered. Please register it before calling this method.", typeof(TV)));
            }

            var vc = Mvx.Resolve <IMvxViewsContainer> ();

            vc.Add(typeof(TVM), _association [typeof(TV)]);

            var viewModel = Mvx.Create <TVM> ();

            try
            {
                var view = this.CreateViewControllerFor <TVM>((object)null);
                viewModel.Factory = this;
                view.ViewModel    = viewModel;
                viewModel.MyView  = (TV)view;
            }
            catch (Exception)
            {
            }

            // Do other initialization here i.e. vm.init();

            return(viewModel);
        }