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; } }
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; }
public void TestHello() { var vm = new FirstViewModel(_applicationVersionService); vm.Hello = _dontPanic; Assert.AreEqual(_dontPanic, vm.Hello); }
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); }
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"]); }
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); } }
public FirstView(Storage storage) { InitializeComponent(); FirstViewModel viewModel = new FirstViewModel(storage); DataContext = viewModel; }
public MainViewModel() { OpenFirstViewModelCommand = new RelayCommand(OpenFirstViewModel); OpenSecondViewModelCommand = new RelayCommand(OpenSecondViewModel); CurrentViewModel = new FirstViewModel(); }
public void ResetCounter_WhenExecuted_ShouldResetCtorCountToZero() { var viewModel = new FirstViewModel(); viewModel.ResetCounter(); Assert.AreEqual(0, viewModel.CtorCount); }
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); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.FirstView); model = (FirstViewModel)this.DataContext; if (!isloggingin) { LoginToFacebook(); } }
public App() { InitializeComponent(); var firstVm = new FirstViewModel(); var firstPage = new FirstPage { ViewModel = firstVm }; MainPage = new NavigationPage(firstPage); }
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); }
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); }
private void ChartTypeTab_Tapped(object sender, int e) { FirstViewModel viewModel = BindingContext.DataContext as FirstViewModel; if (viewModel == null) { return; } viewModel.ChangeChartType(e); chartView.InvalidateSurface(); }
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); }
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); }
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())); }
public override void CreateViewModel() { if (UseEmptyViewModel || string.IsNullOrEmpty(ViewModelInitValueJson)) { VM = new FirstViewModel(); } else { VM = JsonConvert.DeserializeObject <FirstViewModel> (ViewModelInitValueJson); ViewModelPropertyRef(); } VM.AddHostView(ViewModelBase.DefaultViewBaseKey, this); }
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"); }
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); }
public ModuleImpl(IShell shell, FirstViewModel firstViewModel, SecondViewModel secondViewModel) { _shell = shell; _firstViewModel = firstViewModel; _secondViewModel = secondViewModel; }