示例#1
0
        public void LoadView(ViewType typeView)
        {
            switch (typeView)
            {
            case ViewType.Main:
                //загружаем вьюшку, ее вьюмодель
                MainUC        view = new MainUC();
                MainViewModel vm   = new MainViewModel(this);
                //связываем их м/собой
                view.DataContext = vm;
                //отображаем
                this.OutputView.Content = view;
                break;

            case ViewType.First:
                FirstUC        viewF = new FirstUC();
                FirstViewModel vmF   = new FirstViewModel(this);
                viewF.DataContext       = vmF;
                this.OutputView.Content = viewF;
                break;

            case ViewType.Second:
                SecondUC        viewS = new SecondUC();
                SecondViewModel vmS   = new SecondViewModel(this);
                viewS.DataContext       = vmS;
                this.OutputView.Content = viewS;
                break;
            }
        }
示例#2
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            base.OnActionExecuting(context);

            var cookie = context.HttpContext.Request.Cookies;

            var MyLang = cookie[".AspNetCore.Culture"];//cookie["Lang"];

            if (MyLang != null)
            {
                ViewBag.Lang = LangConverter.ConvertFormCode(MyLang);
            }
            else
            {
                ViewBag.Lang = "繁體";
            }

            this.Lang = ViewBag.Lang;

            this.lang_type   = LangConverter.Convert(this.Lang);
            ViewBag.LangType = this.lang_type;

            FirstViewModel = _serviceProvider.GetService <FirstViewModel>();
            FirstViewModel.SetData(this.Lang);
            this.firstViewModel    = FirstViewModel;
            ViewBag.FirstViewModel = FirstViewModel;
        }
示例#3
0
        public void TestHello()
        {
            var vm = new FirstViewModel(_applicationVersionService);

            vm.Hello = _dontPanic;
            Assert.AreEqual(_dontPanic, vm.Hello);
        }
示例#4
0
        public void NavigateBack(FirstViewModel fromViewModel, ResultCode resultCode, FlowResult result)
        {
            var firstViewController            = NavigationViewProvider.GetViewController <FirstViewController, FirstViewModel>(fromViewModel);
            var customFlowNavigationController = (CustomFlowNavigationController)firstViewController.NavigationController;

            NavigateBack(customFlowNavigationController, resultCode, result, true);
        }
示例#5
0
        public void TestFirstViewModelNavigation()
        {
            var firstViewModel  = new FirstViewModel(null);
            var secondViewModel = new SecondViewModel();
            var thirdViewModel  = new ThirdViewModel();
            MainWindowViewModel mainViewModel = new MainWindowViewModel(firstViewModel, secondViewModel, thirdViewModel);

            Assert.AreEqual(firstViewModel, mainViewModel.CurrentViewModel);

            // we are in FirstViewModel, we click "Navigate to second" and in messagebox we click No
            var mock = new Mock <IMessageBoxService>();

            mock.Setup(messageBox => messageBox.Show(It.IsAny <string>(), It.IsAny <string>(), MessageBoxButton.YesNo, MessageBoxImage.Question))
            .Returns(MessageBoxResult.No);
            firstViewModel.MessageBoxService = mock.Object;
            firstViewModel.ShowSecondViewCommand.Execute(true);
            Assert.AreEqual(firstViewModel, mainViewModel.CurrentViewModel);

            // we are in FirstViewModel, we click "Navigate to second" and in the messagebox we click Yes
            mock = new Mock <IMessageBoxService>();
            mock.Setup(messageBox => messageBox.Show(It.IsAny <string>(), It.IsAny <string>(), MessageBoxButton.YesNo, MessageBoxImage.Question))
            .Returns(MessageBoxResult.Yes);
            firstViewModel.MessageBoxService = mock.Object;
            firstViewModel.ShowSecondViewCommand.Execute(true);
            Assert.AreEqual(secondViewModel, mainViewModel.CurrentViewModel);
        }
        public void TestThatPayCommandShowsPayViewModelWithCorrectTotal()
        {
            // Arrange
            base.ClearAll();

            var mockTipService = new Mock <ITipService>();

            mockTipService.Setup(t => t.Calc(It.IsAny <double>(), It.IsAny <int>()))
            .Returns(19.0);

            var mockDispatcher = new MockDispatcher();

            Ioc.RegisterSingleton <IMvxViewDispatcher>(mockDispatcher);
            Ioc.RegisterSingleton <IMvxMainThreadDispatcher>(mockDispatcher);

            var firstViewModel = new FirstViewModel(mockTipService.Object);

            firstViewModel.SubTotal   = 10;
            firstViewModel.Generosity = 12;

            // Act
            firstViewModel.PayCommand.Execute(null);

            // Assert
            Assert.AreEqual(1, mockDispatcher.Requests.Count);
            var request = mockDispatcher.Requests[0];

            Assert.AreEqual(typeof(PayViewModel), request.ViewModelType);
            Assert.AreEqual("29", request.ParameterValues["total"]);
        }
示例#7
0
        public FirstView()
        {
            InitializeComponent();

            // Navigation to detail page
            this.listCharacters.ItemSelected += (object sender, SelectedItemChangedEventArgs e) =>
            {
                TVShowItemViewModel show = (TVShowItemViewModel)e.SelectedItem;
                var detailVm             = new DetailViewModel(show.Id);

                var detailView = new DetailView(detailVm);

                this.Navigation.PushAsync(detailView);
            };


            Device.OnPlatform(WinPhone: () =>
                              listCharacters.ItemTemplate = new DataTemplate(() =>
            {
                var nativeCell = new NativeCell();
                nativeCell.SetBinding(NativeCell.NameProperty, "Name");
                nativeCell.SetBinding(NativeCell.ThumbnailProperty, "Thumbnail");

                return(nativeCell);
            }));

            _vm            = new FirstViewModel();
            BindingContext = _vm;
        }
        public ViewModelLocator()
        {
            try
            {
                var config = new ConfigurationBuilder();
                config.AddJsonFile("autofac.json");
                var module  = new ConfigurationModule(config.Build());
                var builder = new ContainerBuilder();
                builder.RegisterModule(module);
                Container = builder.Build();

                navigationService = Container.Resolve <INavigationService>();
                appViewModel      = Container.Resolve <AppViewModel>();
                firstViewModel    = Container.Resolve <FirstViewModel>();
                secondViewModel   = Container.Resolve <SecondViewModel>();
                thirdViewModel    = Container.Resolve <ThirdViewModel>();

                navigationService.Register <FirstViewModel>(firstViewModel);
                navigationService.Register <SecondViewModel>(secondViewModel);
                navigationService.Register <ThirdViewModel>(thirdViewModel);

                navigationService.Navigate <SecondViewModel>();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#9
0
        public FirstView(Storage storage)
        {
            InitializeComponent();
            FirstViewModel viewModel = new FirstViewModel(storage);

            DataContext = viewModel;
        }
示例#10
0
        public MainViewModel()
        {
            OpenFirstViewModelCommand  = new RelayCommand(OpenFirstViewModel);
            OpenSecondViewModelCommand = new RelayCommand(OpenSecondViewModel);

            CurrentViewModel = new FirstViewModel();
        }
示例#11
0
        public void ResetCounter_WhenExecuted_ShouldResetCtorCountToZero()
        {
            var viewModel = new FirstViewModel();

            viewModel.ResetCounter();

            Assert.AreEqual(0, viewModel.CtorCount);
        }
示例#12
0
 public First()
 {
     InitializeComponent();
     DataContext = new FirstViewModel()
     {
         CloseAction = () => this.Close()
     };
 }
 public IActionResult Submitted(FirstViewModel model)
 {
     if (ModelState.IsValid)
     {
         // can do other stuff here
         return(RedirectToAction(nameof(HomeController.Index), "Home"));
     }
     return(View(model));
 }
        public void NextCommandTest()
        {
            Setup();

            var mainViewModel = new FirstViewModel(Ioc.Resolve <IAppService>());

            mainViewModel.NextCommand.Execute();
            Assert.AreEqual("Hello MvvmCross !back parameter", mainViewModel.Text);
        }
        public void PropertiesTest()
        {
            Setup();

            var mainViewModel = new FirstViewModel(Ioc.Resolve <IAppService>());

            Assert.AreEqual(DateTime.Now.ToString("H:mm:ss"), mainViewModel.Time);
            Assert.AreEqual("Hello MvvmCross !", mainViewModel.Text);
        }
        public void ChangesHello()
        {
            ClearAll();

            var viewModel = new FirstViewModel();
            var hello     = "Test string";

            viewModel.Hello = hello;

            Assert.AreEqual(hello, viewModel.Hello);
        }
 public MainWindowViewModel(FirstViewModel firstViewModel, SecondViewModel secondViewModel, ThirdViewModel thirdViewModel)
 {
     _firstViewModel       = firstViewModel;
     _secondViewModel      = secondViewModel;
     _thirdViewModel       = thirdViewModel;
     ShowFirstViewCommand  = new RelayCommand(ShowFirstView);
     ShowSecondViewCommand = new RelayCommand(ShowSecondView);
     ShowThirdViewCommand  = new RelayCommand(ShowThirdView);
     ShowFirstView();
     Messenger.Default.Register <ChangePage>(this, ChangePage);
 }
示例#18
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.FirstView);
            model = (FirstViewModel)this.DataContext;

            if (!isloggingin)
            {
                LoginToFacebook();
            }
        }
示例#19
0
        public App()
        {
            InitializeComponent();

            var firstVm   = new FirstViewModel();
            var firstPage = new FirstPage {
                ViewModel = firstVm
            };

            MainPage = new NavigationPage(firstPage);
        }
示例#20
0
        public void Ctor_WithOutAurguments_ShouldIncrementCtorCountPropertyOneTime()
        {
            var viewModel  = new FirstViewModel();
            var iterations = new Random().Next(20);

            for (var i = 0; i < iterations; i++)
            {
                viewModel = new FirstViewModel();
            }

            Assert.AreEqual(iterations + 1, viewModel.CtorCount);
        }
示例#21
0
        public StartVmObject(ISynchronizationContextProvider syncContext, IDialogService dialogService, IDataService dataService)
        {
            this.syncContext = syncContext.SynchronizationContext;
            this.Commands    = new Commands(syncContext, this, dialogService, dataService);

            Title = "Viewer";

            Types = GetTypes();


            SelectedViewModel = new FirstViewModel(syncContext, dialogService, dataService, Commands);
        }
示例#22
0
        private void ChartTypeTab_Tapped(object sender, int e)
        {
            FirstViewModel viewModel = BindingContext.DataContext as FirstViewModel;

            if (viewModel == null)
            {
                return;
            }

            viewModel.ChangeChartType(e);
            chartView.InvalidateSurface();
        }
示例#23
0
        public void SetUp()
        {
            base.ClearAll();
            Target          = new FirstViewModel();
            FiredEventNames = new List <string>();
            MockDispatcher  = new MockDispatcher();

            Ioc.RegisterSingleton <IMvxViewDispatcher>(MockDispatcher);
            Ioc.RegisterSingleton <IMvxMainThreadDispatcher>(MockDispatcher);
            Target.PropertyChanged += (sender, e) => FiredEventNames.Add(e.PropertyName);
            Target.Hello            = "Test";
        }
        public void GoCausesNoNavigationAfterChangeHello()
        {
            ClearAll();

            var mockNavigation = CreateMockNavigation();
            var viewModel      = new FirstViewModel();
            var hello          = "Test string";

            viewModel.Hello = hello;

            Assert.AreEqual(0, mockNavigation.NavigateRequests.Count);
        }
示例#25
0
        public override void Attach(ViewModelBase viewModel)
        {
            FirstViewModel vm = (FirstViewModel)viewModel;

            vm.RC_DefaultCommand.Subscribe(_ => {
                DefaultCommand((FirstViewModel)viewModel);
            }).AddTo(viewModel.baseAttachDisposables);
            vm.RC_AddNum.Subscribe <AddNumCommand> (command => {
                command.Sender = viewModel;
                AddNum((FirstViewModel)viewModel, command);
            }).AddTo(viewModel.baseAttachDisposables);
        }
示例#26
0
 public void Install(IPluginInfo pluginInfo)
 {
     if (GlobalConfig.Ins.AlwaysShow)
     {
         _firstVm   = new FirstViewModel();
         _dockingVm = new DockingPaneViewModel(_firstVm)
         {
             Header = "面板的标题",
         };
         M.DockingManager.InsertPane(_dockingVm);
     }
     //系统设置中插件的设置界面
     M.SettingManager.AddPluginSettingItem("MyPluginSetting", new SettingItem("我的插件", new SettingView()));
 }
示例#27
0
        public override void CreateViewModel()
        {
            if (UseEmptyViewModel || string.IsNullOrEmpty(ViewModelInitValueJson))
            {
                VM = new FirstViewModel();
            }
            else
            {
                VM = JsonConvert.DeserializeObject <FirstViewModel> (ViewModelInitValueJson);
                ViewModelPropertyRef();
            }

            VM.AddHostView(ViewModelBase.DefaultViewBaseKey, this);
        }
示例#28
0
        public FirstPage()
        {
            InitializeComponent();

            BindingContext = new FirstViewModel();

            picker.ItemsSource = new List <string>
            {
                "Escolha um dono", "Matugas", "Eduardo", "Ricardo"
            };
            picker.SelectedIndex = 0;

            slider.ValueChanged += Slider_ValueChanged;
        }
        public ViewModelLocator()
        {
            navigationService = new NavigationService();

            appViewModel    = new AppViewModel(navigationService);
            firstViewModel  = new FirstViewModel();
            secondViewModel = new SecondViewModel(navigationService);
            thirdViewModel  = new ThirdViewModel();

            navigationService.Register("First", firstViewModel);
            navigationService.Register("Second", secondViewModel);
            navigationService.Register("Third", thirdViewModel);

            navigationService.Navigate("First");
        }
示例#30
0
        public void TestSecondViewModelAndThirdViewModelNavigation()
        {
            var firstViewModel  = new FirstViewModel(null);
            var secondViewModel = new SecondViewModel();
            var thirdViewModel  = new ThirdViewModel();
            MainWindowViewModel mainViewModel = new MainWindowViewModel(firstViewModel, secondViewModel, thirdViewModel);

            mainViewModel.CurrentViewModel = secondViewModel;

            secondViewModel.ShowThirdViewCommand.Execute(null);
            Assert.AreEqual(thirdViewModel, mainViewModel.CurrentViewModel);

            thirdViewModel.ShowFirstViewCommand.Execute(null);
            Assert.AreEqual(firstViewModel, mainViewModel.CurrentViewModel);
        }
示例#31
0
 public ModuleImpl(IShell shell, FirstViewModel firstViewModel, SecondViewModel secondViewModel)
 {
     _shell = shell;
     _firstViewModel = firstViewModel;
     _secondViewModel = secondViewModel;
 }