コード例 #1
0
        private void OnEditProductCommand(object param)
        {
            var p = param as Product;

            if (p != null)
            {
                // Opens the ProductEditView on top of ProductEditViewModel
                // Note that this viewmodel implements IViewKeyAware so that it will have the same ViewKey as its View
                var navigationInfo = NavigationInfo.CreateComplex(ViewId.ProductEdit, ViewKey, new ProductEditViewModel(p));
                Singletons.NavigationService.NavigateTo <ProductEditView>(navigationInfo);
            }
        }
コード例 #2
0
            public void CannotNavigateAndAttachNewViewWithNotTopMostParentView()
            {
                // Prepare
                var navigationInfo1 = NavigationInfo.CreateSimple("viewKey1");
                var navigationInfo2 = NavigationInfo.CreateComplex("viewKey2", navigationInfo1.ViewKey);
                var navigationInfo3 = NavigationInfo.CreateComplex("viewKey3", navigationInfo1.ViewKey);

                _navigationService.NavigateTo <UserControl>(navigationInfo1);
                _navigationService.NavigateTo <UserControl>(navigationInfo2);

                // Act
                _navigationService.NavigateTo <UserControl>(navigationInfo3);

                // Verify
            }
コード例 #3
0
            public void CanShowModal()
            {
                // Prepare
                var navigationInfo      = NavigationInfo.CreateSimple("viewKey");
                var modalNavigationInfo = NavigationInfo.CreateComplex("modalViewKey", navigationInfo.ViewKey);
                var oldViewInfo         = _navigationService.NavigateTo <UserControl>(navigationInfo);

                // Act
                var modalResult = _navigationService.ShowModal <UserControl, bool>(modalNavigationInfo);

                // Verify
                Assert.AreEqual(modalResult.ViewInfo, _navigationService.CurrentView);
                Assert.IsInstanceOfType(_navigationService.CurrentView.View, typeof(ModalHostControl));
                Assert.IsTrue(oldViewInfo.View.Visibility == Visibility.Visible);
            }
コード例 #4
0
ファイル: AboutView.xaml.cs プロジェクト: GasyTek/Lakana
        private void SendMailClick(object sender, RoutedEventArgs e)
        {
            // HOW TO : open a modal view on top of another one
            // Here is an example of a modal custom view.
            // The modal view returns a Task<TResult>, that means that you can use the C#5 async/await pattern to improve this code.
            // Notice that you have to use TaskScheduler.FromCurrentSynchronizationContext()
            // in order to use the UI thread synchronization context
            var navigationInfo = NavigationInfo.CreateComplex(ViewId.SendMail, ViewId.About, false);
            var modalResult    = Singletons.NavigationService.ShowModal <SendMailView, string>(navigationInfo);

            modalResult.Result.ContinueWith(r =>
            {
                txtDisplayModalResult.Text = "Modal Result : " + r.Result;
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
コード例 #5
0
            public void WhenModalViewIsDisplayedItsParentIsVisibleAndDisabled()
            {
                // Prepare
                var parentNavigationInfo = NavigationInfo.CreateSimple("parentViewKey");
                var modalNavigationInfo  = NavigationInfo.CreateComplex("modalViewKey", parentNavigationInfo.ViewKey);
                var parentViewInfo       = _navigationService.NavigateTo <UserControl>(parentNavigationInfo);

                // Act
                var modalResult = _navigationService.ShowModal <UserControl, bool>(modalNavigationInfo);

                // Verify
                Assert.IsTrue(modalResult.ViewInfo.View.Visibility == Visibility.Visible);
                Assert.IsTrue(parentViewInfo.View.Visibility == Visibility.Visible);
                Assert.IsFalse(parentViewInfo.View.IsEnabled);
            }
コード例 #6
0
            public void CanNavigateAndAttachNewViewWithViewKeyAwareViewModelToParentView()
            {
                // Prepare
                var fakeViewModel        = new FakeViewKeyAwareViewModel();
                var parentNavigationInfo = NavigationInfo.CreateSimple("parentViewKey");
                var childNavigationInfo  = NavigationInfo.CreateComplex("childViewKey", parentNavigationInfo.ViewKey, fakeViewModel);

                _navigationService.NavigateTo <UserControl>(parentNavigationInfo);

                // Act
                var expectedViewInfo = _navigationService.NavigateTo <UserControl>(childNavigationInfo);

                // Verify
                Assert.IsNotNull(expectedViewInfo.View.DataContext);
                Assert.AreEqual(childNavigationInfo.ViewKey, ((IViewKeyAware)expectedViewInfo.View.DataContext).ViewKey);
            }
コード例 #7
0
            public void CanNavigateAndAttachNewViewWithParentView()
            {
                // Prepare
                var parentNavigationInfo = NavigationInfo.CreateSimple("parentViewKey");
                var childNavigationInfo  = NavigationInfo.CreateComplex("childViewKey", parentNavigationInfo.ViewKey);
                var oldViewInfo          = _navigationService.NavigateTo <UserControl>(parentNavigationInfo);

                // Act
                var expectedViewInfo = _navigationService.NavigateTo <UserControl>(childNavigationInfo);

                // Verify
                Assert.AreSame(expectedViewInfo.View, _navigationService.CurrentView.View);
                Assert.IsTrue(_navigationService.RootPanel.Children.Contains(expectedViewInfo.View));
                Assert.IsTrue(expectedViewInfo.View.Visibility == Visibility.Visible);
                Assert.IsTrue(oldViewInfo.View.Visibility == Visibility.Collapsed);
            }
コード例 #8
0
            public void CannotCloseNotTopMostView()
            {
                // Prepare
                var navigationInfo1 = NavigationInfo.CreateSimple("viewKey1");
                var navigationInfo2 = NavigationInfo.CreateComplex("viewKey2", navigationInfo1.ViewKey);
                var navigationInfo3 = NavigationInfo.CreateComplex("viewKey3", navigationInfo2.ViewKey);

                _navigationService.NavigateTo <UserControl>(navigationInfo1);
                _navigationService.NavigateTo <UserControl>(navigationInfo2);
                _navigationService.NavigateTo <UserControl>(navigationInfo3);

                // Act
                _navigationService.Close("viewKey2");

                // Verify
            }
コード例 #9
0
            public void CannotNavigateAndAttachExistingViewWithParentView()
            {
                // Prepare
                var navigationInfo       = NavigationInfo.CreateSimple("viewKey");
                var parentNavigationInfo = NavigationInfo.CreateSimple("parentViewKey");

                _navigationService.NavigateTo <UserControl>(navigationInfo);
                _navigationService.NavigateTo <UserControl>(parentNavigationInfo);

                // Act
                var notAllowedNavigationInfo = NavigationInfo.CreateComplex(navigationInfo.ViewKey, parentNavigationInfo.ViewKey);

                _navigationService.NavigateTo <UserControl>(notAllowedNavigationInfo);

                // Verify
            }
コード例 #10
0
            public void CanShowCloseableViewSelection()
            {
                // Prepare
                var navigationInfo1 = NavigationInfo.CreateSimple("viewKey1");
                var navigationInfo2 = NavigationInfo.CreateComplex("viewKey2", navigationInfo1.ViewKey, new FakeDirtyViewModel());

                _navigationService.NavigateTo <UserControl>(navigationInfo1);
                _navigationService.NavigateTo <UserControl>(navigationInfo2);

                // Act
                _navigationService.CloseApplication();

                // Verify
                Assert.IsInstanceOfType(_navigationService.CurrentView.View, typeof(ModalHostControl));
                Assert.IsInstanceOfType(((ModalHostControl)_navigationService.CurrentView.View).ModalContent, typeof(ShutdownApplicationControl));
            }
コード例 #11
0
            public void LeavingParentActiveAwareViewSupported()
            {
                // Prepare
                var activeAwareViewModelMock = new Mock <IActiveAware>();
                var parentNavigationInfo     = NavigationInfo.CreateSimple("parentViewKey", activeAwareViewModelMock.Object);
                var navigationInfo           = NavigationInfo.CreateComplex("viewKey", "parentViewKey");

                _navigationService.NavigateTo <UserControl>(parentNavigationInfo);

                // Act
                _navigationService.NavigateTo <UserControl>(navigationInfo);

                // Verify
                activeAwareViewModelMock.Verify(m => m.OnDeactivating(), Times.Exactly(1));
                activeAwareViewModelMock.Verify(m => m.OnDeactivated(), Times.Exactly(1));
            }
コード例 #12
0
            public void ShowModalActiveAwareViewSupported()
            {
                // Prepare
                var navigationInfo           = NavigationInfo.CreateSimple("viewKey");
                var activeAwareViewModelMock = new Mock <IActiveAware>();
                var modalNavigationInfo      = NavigationInfo.CreateComplex("modalViewKey", navigationInfo.ViewKey, activeAwareViewModelMock.Object);

                _navigationService.NavigateTo <UserControl>(navigationInfo);

                // Act
                _navigationService.ShowModal <UserControl, string>(modalNavigationInfo);

                // Verify
                activeAwareViewModelMock.Verify(m => m.OnActivating(), Times.Exactly(1));
                activeAwareViewModelMock.Verify(m => m.OnActivated(), Times.Exactly(1));
            }
コード例 #13
0
            public void CanRaiseClosingApplicationShownEvent()
            {
                // Prepare
                var eventRaised     = false;
                var navigationInfo1 = NavigationInfo.CreateSimple("viewKey1");
                var navigationInfo2 = NavigationInfo.CreateComplex("viewKey2", navigationInfo1.ViewKey, new FakeDirtyViewModel());

                _navigationService.NavigateTo <UserControl>(navigationInfo1);
                _navigationService.NavigateTo <UserControl>(navigationInfo2);

                // Act
                _navigationService.ShutdownApplicationShown += (sender, e) => eventRaised = true;
                _navigationService.CloseApplication();

                // Verify
                Assert.IsTrue(eventRaised);
            }
コード例 #14
0
            public void NavigateMultipleTimeToNotTopMostViewDoNotFireActivation()
            {
                // Prepare
                var activeAwareViewModelMock = new Mock <IActiveAware>();
                var parentNavigationInfo     = NavigationInfo.CreateSimple("parentViewKey", activeAwareViewModelMock.Object);
                var navigationInfo           = NavigationInfo.CreateComplex("viewKey", "parentViewKey");

                _navigationService.NavigateTo <UserControl>(parentNavigationInfo);
                _navigationService.NavigateTo <UserControl>(navigationInfo);

                // Act
                _navigationService.NavigateTo <UserControl>(parentNavigationInfo);

                // Verify
                activeAwareViewModelMock.Verify(m => m.OnActivating(), Times.Exactly(1));
                activeAwareViewModelMock.Verify(m => m.OnActivated(), Times.Exactly(1));
            }
コード例 #15
0
            public void CanRetrieveModalResult()
            {
                // Prepare
                var testedModalResult   = "";
                var navigationInfo      = NavigationInfo.CreateSimple("viewKey");
                var modalNavigationInfo = NavigationInfo.CreateComplex("modalViewKey", navigationInfo.ViewKey);

                _navigationService.NavigateTo <UserControl>(navigationInfo);

                // Act
                var modalResult = _navigationService.ShowModal <UserControl, string>(modalNavigationInfo);

                modalResult.Result.ContinueWith(r => testedModalResult = r.Result);
                _navigationService.Close(modalResult.ViewInfo.ViewKey, "ModalResult");  // Close the modal view and provide the modal result

                // Verify
                Assert.AreEqual("ModalResult", testedModalResult);
            }
コード例 #16
0
            public void CanNavigateAndAttachSameViewToSameParentManySuccessiveTimes()
            {
                // Prepare
                var parentNavigationInfo = NavigationInfo.CreateSimple("parentViewKey");
                var childNavigationInfo  = NavigationInfo.CreateComplex("childViewKey", parentNavigationInfo.ViewKey);
                var navigationInfo       = NavigationInfo.CreateSimple("viewKey");

                _navigationService.NavigateTo <UserControl>(parentNavigationInfo);
                var childViewInfo = _navigationService.NavigateTo <UserControl>(childNavigationInfo);

                _navigationService.NavigateTo <UserControl>(navigationInfo);

                // Act
                var expectedViewInfo = _navigationService.NavigateTo <UserControl>(childNavigationInfo);

                // Verify
                Assert.AreEqual(expectedViewInfo, _navigationService.CurrentView);
                Assert.AreSame(expectedViewInfo.View, childViewInfo.View);
            }
コード例 #17
0
            public void NavigateToNotTopMostViewMakesTheTopMostViewOfTheStackTheCurrentView()
            {
                // Prepare
                var navigationInfo1  = NavigationInfo.CreateSimple("viewKey1");
                var navigationInfo2  = NavigationInfo.CreateComplex("viewKey2", navigationInfo1.ViewKey);
                var navigationInfo3  = NavigationInfo.CreateComplex("viewKey3", navigationInfo2.ViewKey);
                var oldViewInfo1     = _navigationService.NavigateTo <UserControl>(navigationInfo1);
                var oldViewInfo2     = _navigationService.NavigateTo <UserControl>(navigationInfo2);
                var expectedViewInfo = _navigationService.NavigateTo <UserControl>(navigationInfo3);

                // Act
                _navigationService.NavigateTo("viewKey1");

                // Verify
                Assert.AreSame(expectedViewInfo.View, _navigationService.CurrentView.View);
                Assert.IsTrue(_navigationService.RootPanel.Children.Contains(expectedViewInfo.View));
                Assert.IsTrue(expectedViewInfo.View.Visibility == Visibility.Visible);
                Assert.IsTrue(oldViewInfo1.View.Visibility == Visibility.Collapsed);
                Assert.IsTrue(oldViewInfo2.View.Visibility == Visibility.Collapsed);
            }
コード例 #18
0
            public void CanNavigateToModalViewUsingViewKey()
            {
                // Prepare
                var navigationInfo       = NavigationInfo.CreateSimple("viewKey");
                var parentNavigationInfo = NavigationInfo.CreateSimple("parentViewKey");
                var modalNavigationInfo  = NavigationInfo.CreateComplex("modalViewKey", parentNavigationInfo.ViewKey);

                _navigationService.NavigateTo <UserControl>(navigationInfo);
                var parentViewInfo = _navigationService.NavigateTo <UserControl>(parentNavigationInfo);

                _navigationService.ShowModal <UserControl, bool>(modalNavigationInfo);

                // Act
                var expectedViewInfo = _navigationService.NavigateTo("modalViewKey");

                // Verify
                Assert.AreEqual(expectedViewInfo, _navigationService.CurrentView);
                Assert.IsTrue(expectedViewInfo.View.Visibility == Visibility.Visible);
                Assert.IsTrue(parentViewInfo.View.Visibility == Visibility.Visible);
                Assert.IsFalse(parentViewInfo.View.IsEnabled);
            }
コード例 #19
0
            public void OnlyTopMostAndCloseableViewsAreProposed()
            {
                // Prepare
                var navigationInfo1 = NavigationInfo.CreateSimple("viewKey1");
                var navigationInfo2 = NavigationInfo.CreateComplex("viewKey2", navigationInfo1.ViewKey, new FakeDirtyViewModel());
                var navigationInfo3 = NavigationInfo.CreateSimple("viewKey3", new FakeDirtyViewModel());

                _navigationService.NavigateTo <UserControl>(navigationInfo1);
                var expectedViewInfo1 = _navigationService.NavigateTo <UserControl>(navigationInfo2);
                var expectedViewInfo2 = _navigationService.NavigateTo <UserControl>(navigationInfo3);

                // Act
                _navigationService.CloseApplication();

                // Verify
                var closeApplicationControl = (ShutdownApplicationControl)((ModalHostControl)_navigationService.CurrentView.View).ModalContent;

                Assert.IsTrue(closeApplicationControl.NbCloseableViews == 2);
                Assert.IsTrue(closeApplicationControl.ItemsSource.Cast <ViewInfo>().ToList().Contains(expectedViewInfo1));
                Assert.IsTrue(closeApplicationControl.ItemsSource.Cast <ViewInfo>().Contains(expectedViewInfo2));
            }
コード例 #20
0
            public void CanRestoreModalViewWhenNavigatingToNotTopMostView()
            {
                // Prepare
                var navigationInfo       = NavigationInfo.CreateSimple("viewKey");
                var parentNavigationInfo = NavigationInfo.CreateSimple("parentViewKey");
                var modalNavigationInfo  = NavigationInfo.CreateComplex("modalViewKey", parentNavigationInfo.ViewKey);

                _navigationService.NavigateTo <UserControl>(parentNavigationInfo);
                var modalResult = _navigationService.ShowModal <UserControl, bool>(modalNavigationInfo);

                _navigationService.NavigateTo <UserControl>(navigationInfo);

                // Act
                var parentViewInfo = _navigationService.NavigateTo <UserControl>(parentNavigationInfo);

                // Verify
                Assert.AreEqual(modalResult.ViewInfo, _navigationService.CurrentView);
                Assert.IsTrue(modalResult.ViewInfo.View.Visibility == Visibility.Visible);
                Assert.IsTrue(parentViewInfo.View.Visibility == Visibility.Visible);
                Assert.IsFalse(parentViewInfo.View.IsEnabled);
            }