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 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 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 SecondPage() { InitializeComponent(); var viewModel = new SecondViewModel(); BindingContext = viewModel; }
public MainViewModel(ILocationService locationService, FirstViewModel first, SecondViewModel second, INavigationService navigationService) { _locationService = locationService; this.FirstViewModel = first; this.SecondViewModel = second; Location = _locationService.GetLocation(); _navigationService = navigationService; }
public void TitleTest() { Setup(); var secondViewModel = new SecondViewModel(); Assert.AreEqual("Second page, ", secondViewModel.Title); }
private void SwitchView(object sender, outedEventArgs e) { var view = new SecondView(); var model = new SecondViewModel(); view.DataContext = model; MainContent.Content = view; }
public void ParameterTest() { Setup(); var secondViewModel = new SecondViewModel(); secondViewModel.Prepare("test"); secondViewModel.Initialize(); Assert.AreEqual("Second page, test", secondViewModel.Title); }
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); }
public override void CreateViewModel() { if (UseEmptyViewModel || string.IsNullOrEmpty(ViewModelInitValueJson)) { VM = new SecondViewModel(); } else { VM = JsonConvert.DeserializeObject <SecondViewModel> (ViewModelInitValueJson); ViewModelPropertyRef(); } VM.AddHostView(ViewModelBase.DefaultViewBaseKey, this); }
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 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 SecondView() { InitializeComponent(); context = new SecondViewModel(); DataContext = context; Height = double.NaN; Width = double.NaN; context.ChangeWindowSizeEvent += ChangeWindowSize; context.RectangleMouseDownEvent += RectangleCanvasSetStartPoint; context.RectangleMouseMoveEvent += RectangleCanvasMouseMove; context.ShowMainPageEvent += ShowMainPage; context.ShowWaitingPageEvent += ShowWaitingPage; context.DeleteRectangleSelectionEvent += DeleteSelection; }
public MainWindowViewModel( FirstViewModel firstViewModel, SecondViewModel secondViewModel, ThirdViewModel thirdViewModel, IMessenger messenger) { _firstViewModel = firstViewModel; _secondViewModel = secondViewModel; _thirdViewModel = thirdViewModel; _messenger = messenger; messenger.Register <ChangePageMessage>(this, ChangePage); ShowFirstViewCommand = new RelayCommand(ShowFirstView); ShowSecondViewCommand = new RelayCommand(ShowSecondView); ShowThirdViewCommand = new RelayCommand(ShowThirdView); }
public override void Attach(ViewModelBase viewModel) { SecondViewModel vm = (SecondViewModel)viewModel; vm.RC_StringCommand.Subscribe <StringCommandCommand> (command => { command.Sender = viewModel; StringCommand((SecondViewModel)viewModel, command); }).AddTo(viewModel.baseAttachDisposables); vm.RC_IntCommand.Subscribe <IntCommandCommand> (command => { command.Sender = viewModel; IntCommand((SecondViewModel)viewModel, command); }).AddTo(viewModel.baseAttachDisposables); vm.RC_SimpleCommand.Subscribe(_ => { SimpleCommand((SecondViewModel)viewModel); }).AddTo(viewModel.baseAttachDisposables); }
public void ViewModelViewHost_View_Should_Stay_In_Sync_With_ViewModel() { var defaultContent = new TextBlock(); var host = new ViewModelViewHost { DefaultContent = defaultContent, PageTransition = null }; var root = new TestRoot { Child = host }; Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded); Assert.NotNull(host.Content); Assert.Equal(typeof(TextBlock), host.Content.GetType()); Assert.Equal(defaultContent, host.Content); var first = new FirstViewModel(); host.ViewModel = first; Assert.NotNull(host.Content); Assert.Equal(typeof(FirstView), host.Content.GetType()); Assert.Equal(first, ((FirstView)host.Content).DataContext); Assert.Equal(first, ((FirstView)host.Content).ViewModel); var second = new SecondViewModel(); host.ViewModel = second; Assert.NotNull(host.Content); Assert.Equal(typeof(SecondView), host.Content.GetType()); Assert.Equal(second, ((SecondView)host.Content).DataContext); Assert.Equal(second, ((SecondView)host.Content).ViewModel); host.ViewModel = null; Assert.NotNull(host.Content); Assert.Equal(typeof(TextBlock), host.Content.GetType()); Assert.Equal(defaultContent, host.Content); host.ViewModel = first; Assert.NotNull(host.Content); Assert.Equal(typeof(FirstView), host.Content.GetType()); Assert.Equal(first, ((FirstView)host.Content).DataContext); Assert.Equal(first, ((FirstView)host.Content).ViewModel); }
public override void Initialize(ViewModelBase viewModel) { if (viewModel != null) { VM = (SecondViewModel)viewModel; VM.AddHostView(ViewModelBase.DefaultViewBaseKey, this); } else { if (AutoCreateViewModel && VM == null) { CreateViewModel(); } } base.Initialize(VM); }
public void GoForwardTestCase() { NavigationViewModel firstViewModel = null; SecondViewModel secondViewModel = null; Given("Init view-model", frame => ViewModelBase.CreateViewModel <NavigationViewModel>(frame)) .And("Navigate NavigationPage", viewModel => { firstViewModel = viewModel; return(ViewModelBase.Navigate <NavigationPage>(viewModel)); }) .And("Check success Navigate method for NavigationPage", nResult => nResult.HasSuccessAndGetViewModel()) .AndAsync("Check load NavigationPage", async viewModel => await WaitLoadPageAndCheckViewModelAsync <NavigationPage, ViewModelBase>(viewModel)) .And("Navigate SecondPage", viewModel => viewModel.Navigate <SecondPage, SecondViewModel>()) .And("Check success Navigate method for SecondPage", nResult => nResult.HasSuccessAndGetViewModel()) .AndAsync("Check load SecondPage", async viewModel => { await WaitLoadPageAndCheckViewModelAsync <SecondPage, SecondViewModel>(viewModel); secondViewModel = viewModel; }) .And("Check CanGoBack", () => Assert.IsTrue(secondViewModel.NavigationManager.CanGoBack, "CanGoBack must be true")) .And("Execute GoBack", () => secondViewModel.NavigationManager.GoBack()) .AndAsync("Check load NavigationPage", async() => await WaitLoadPageAndCheckViewModelAsync <NavigationPage, NavigationViewModel>(firstViewModel)) .And("Check CanGoForward", () => Assert.IsTrue(firstViewModel.NavigationManager.CanGoForward, "CanGoForward must be true")) .When("Execute GoForward", () => secondViewModel.NavigationManager.GoForward()) .ThenAsync("Check load NavigationPage", async() => await WaitLoadPageAndCheckViewModelAsync <SecondPage, SecondViewModel>(secondViewModel)) .And("Check properties", () => { Assert.IsFalse(firstViewModel.IsNavigated, "IsNavigated must be false"); Assert.IsFalse(firstViewModel.IsLoaded, "IsNavigated must be false"); Assert.IsTrue(firstViewModel.IsLeaved, "IsNavigated must be true"); Assert.AreEqual(6, firstViewModel.MethodCallLog.Count, "long call log should be 5"); Assert.AreEqual("OnGoPageAsync", firstViewModel.MethodCallLog[0], "1st must be called OnGoPageAsync"); Assert.AreEqual("OnLoadPageAsync", firstViewModel.MethodCallLog[1], "2st must be called OnLoadPageAsync"); Assert.AreEqual("OnLeavePageAsync", firstViewModel.MethodCallLog[2], "3st must be called OnLeavePageAsync"); Assert.AreEqual("OnGoPageAsync", firstViewModel.MethodCallLog[3], "1st must be called OnGoPageAsync"); Assert.AreEqual("OnLoadPageAsync", firstViewModel.MethodCallLog[4], "2st must be called OnLoadPageAsync"); Assert.AreEqual("OnLeavePageAsync", firstViewModel.MethodCallLog[5], "3st must be called OnLeavePageAsync"); }) .Run <TestWindow>(window => window.Frame, Timeouts.Second.Ten); }
public override void SetViewModel(ViewModelBase viewModel) { VM = (SecondViewModel)viewModel; }
public SecondView() { InitializeComponent(); DataContext = new SecondViewModel(ApplicationService.Instance.EventAggregator); }
public YourViewModelDataSource(ViewModel viewModel, SecondViewModel secondViewModel) { this.viewModel = viewModel; this.secondViewModel = secondViewModel; }
public CombinedViewModel() { this.FirstViewModel = new FirstViewModel(); this.SecondViewModel = new SecondViewModel(); }
public MainViewModel() { this.FirstViewModel = new FirstViewModel(); this.SecondViewModel = new SecondViewModel(); }
protected override void OnAppearing() { BindingContext = new SecondViewModel(); base.OnAppearing(); }
public void AddSecondViewModel(SecondViewModel vm) { _secondViewModels.Add(vm); vm.PropertyChanged += (s, e) => OnPropertyChanged("myProperty"); OnPropertyChanged("myProperty"); }
public MainViewModel() { firstViewModel = new FirstViewModel(); secondViewModel = new SecondViewModel(); }
/* */ public virtual void SimpleCommand(SecondViewModel viewModel) { }
/* */ public virtual void IntCommand(SecondViewModel viewModel, IntCommandCommand command) { }
/* */ public virtual void StringCommand(SecondViewModel viewModel, StringCommandCommand command) { }
public ModuleImpl(IShell shell, FirstViewModel firstViewModel, SecondViewModel secondViewModel) { _shell = shell; _firstViewModel = firstViewModel; _secondViewModel = secondViewModel; }