Exemplo n.º 1
0
        public GuideList()
        {
            this.InitializeComponent();

            viewModel = DataContext as INavigableViewModel;
            viewModel.SetNavigationHelper(new NavigationHelper(this));
        }
        public async Task Extended_interface_contract_changes_can_be_detected()
        {
            var             ct        = CancellationToken.None;
            IStackNavigator navigator = new BlindStackNavigator();

            // If the extension methods available in the abstraction package change their signatures, we get compilation errors here.

            TestVM vmAfterNavigate = await navigator.Navigate(ct, () => new TestVM(), suppressTransition : false);

            TestVM vmAfterNavigateAndClear = await navigator.NavigateAndClear(ct, () => new TestVM(), suppressTransition : false);

            INavigableViewModel vm = navigator.GetActiveViewModel();
            bool canGoBack         = navigator.CanNavigateBack();

            // Navigate twice so that RemovePrevious works.
            await navigator.Navigate(ct, () => new TestVM(), suppressTransition : false);

            await navigator.Navigate(ct, () => new TestVM(), suppressTransition : false);

            await navigator.RemovePrevious(ct);

            bool didNavigateBack = await navigator.TryNavigateBackTo <TestVM>(ct);

            await navigator.ProcessRequest(ct, StackNavigatorRequest.GetNavigateRequest(() => new TestVM(), false, false));

            IObservable <EventPattern <StackNavigatorEventArgs> > ob1 = navigator.ObserveStateChanged();
            IObservable <StackNavigatorState> ob2 = navigator.ObserveCurrentState();
        }
Exemplo n.º 3
0
 private void _closeBooking(IEntity closedEntity)
 {
     try
     {
         Logger.Log("=Fermeture de réservation (onglet)=");
         int entityIndex = -1;
         int i           = 0;
         foreach (IEntity entity in _currentEntities)
         {
             if (entity.Equals(closedEntity))
             {
                 entityIndex = i;
                 break;
             }
             i++;
         }
         if (entityIndex != -1 && closedEntity is INavigableViewModel)
         {
             INavigableViewModel bookingVM = closedEntity as INavigableViewModel;
             bookingVM.NextCalled      -= _nextCalled;
             bookingVM.PreviousCalled  -= _prevCalled;
             bookingVM.MessageReceived -= _messageReceived;
             _currentEntities.RemoveAt(entityIndex);
         }
     }
     catch (Exception ex)
     {
         Logger.Log(ex);
     }
 }
Exemplo n.º 4
0
 public HomeViewModel(INavigableViewModel navigableViewModel)
     : base(navigableViewModel)
 {
     Items = new[]
     {
         new SelectableViewModel(true, "3", "Bill Gates", "A chef"),
         new SelectableViewModel(false, "12", "Steve White", "An expert on logistic")
     };
 }
Exemplo n.º 5
0
 private void _node_shutdown(INavigableViewModel navigableVM)
 {
     if (navigableVM != null)
     {
         navigableVM.NextCalled     -= _nextCalled;
         navigableVM.PreviousCalled -= _prevCalled;
         navigableVM.Shutdown       -= _nodeShutdown;
     }
 }
Exemplo n.º 6
0
        public LoginPage()
        {
            this.InitializeComponent();

            viewModel = DataContext as INavigableViewModel;
            viewModel.SetNavigationHelper(new NavigationHelper(this));   

            this.SpinningAnimation.Begin();
        }
Exemplo n.º 7
0
 private void _prev(INavigableViewModel navigableVM)
 {
     try
     {
         LinkedListNode <INavigableViewModel> currentNode = _navigation.Find(navigableVM);
         if (currentNode.Previous != null)
         {
             currentNode = currentNode.Previous;
             _currentEntities[_currentEntitiesView.CurrentPosition] = currentNode.Value;
         }
     }
     catch (Exception ex)
     {
         Logger.Log(ex);
     }
 }
Exemplo n.º 8
0
 private void _next(INavigableViewModel navigableVM)
 {
     try
     {
         LinkedListNode <INavigableViewModel> currentNode = _navigation.Find(navigableVM);
         if (currentNode.Next != null)
         {
             currentNode = currentNode.Next;
             _currentEntities[_currentEntitiesView.CurrentPosition] = currentNode.Value;
             currentNode.Value.NextCalled     += _nextCalled;
             currentNode.Value.PreviousCalled += _prevCalled;
             currentNode.Value.Shutdown       += _nodeShutdown;
         }
     }
     catch (Exception ex)
     {
         Logger.Log(ex);
     }
 }
        public async Task Interface_contract_changes_can_be_detected()
        {
            var             ct        = CancellationToken.None;
            IStackNavigator navigator = new BlindStackNavigator();

            // If the core contract changes, we get compilation errors here.
            INavigableViewModel vmAfterNavigate = await navigator.Navigate(ct, StackNavigatorRequest.GetNavigateRequest(() => new TestVM(), false, false));

            INavigableViewModel vmAfterBack = await navigator.NavigateBack(ct);

            await navigator.Clear(ct);

            // Navigate twice so that RemoveEntries works.
            await navigator.Navigate(ct, StackNavigatorRequest.GetNavigateRequest(() => new TestVM(), false, false));

            await navigator.Navigate(ct, StackNavigatorRequest.GetNavigateRequest(() => new TestVM(), false, false));

            await navigator.RemoveEntries(ct, new int[] { 0 }.AsEnumerable());
        }
Exemplo n.º 10
0
		public TimeViewModel(INavigableViewModel navigableViewModel)
			: base(navigableViewModel)
		{
			timer = TimerFactory.StartAndExecute(TimeSpan.FromSeconds(1), () => CurrentTime = DateTime.Now);
		}
Exemplo n.º 11
0
        protected override async Task <object> InnerNavigateAndGetView(INavigableViewModel viewModel)
        {
            var request = State.LastRequest;

            var viewType = request.ViewType;

            if (viewType == null)
            {
                if (_registrations.TryGetValue(request.ViewModelType, out var registeredViewType))
                {
                    viewType = registeredViewType;
                }
                else
                {
                    throw new KeyNotFoundException($"Can't process navigation because no view is registered with '{request.ViewModelType.FullName}'. Provide a view type in the NavigationRequest or provide a registration in the constructor.");
                }
            }

            var view = await Dispatcher.RunTaskAsync(CoreDispatcherPriority.High, UINavigate);

            if (view != null && !(request.SuppressTransitions ?? false))
            {
                // There's no way to know when the animation ends. So, we assume it runs for 250ms.
                await Task.Delay(millisecondsDelay : 250);
            }

            // The returned view is stored in the Stack.
            return(view);

            async Task <Page> UINavigate()
            {
                try
                {
                    var overrideInfo = request.SuppressTransitions ?? false
                                                ? (NavigationTransitionInfo) new SuppressNavigationTransitionInfo()
                                                : (NavigationTransitionInfo) new SlideNavigationTransitionInfo()
                    {
                        Effect = SlideNavigationTransitionEffect.FromRight
                    };

                    var navigationResult = await WaitForNavigationResult(() =>
                    {
                        var isNavigationSuccessful = _frame.Navigate(viewType, parameter: null, overrideInfo);
                        if (!isNavigationSuccessful)
                        {
                            if (_logger.IsEnabled(LogLevel.Error))
                            {
                                _logger.LogError($"Failed frame navigation to view '{viewType.FullName}'.");
                            }
                        }
                    });

                    if (request.ClearBackStack ?? false)
                    {
                        _frame.BackStack?.Clear();
                    }

                    if (navigationResult.Content is Page page)
                    {
                        var viewTcs = new TaskCompletionSource <Page>();
                        page.Loaded += OnPageLoaded;

                        void OnPageLoaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
                        {
                            page.Loaded -= OnPageLoaded;
                            viewTcs.SetResult(page);
                        }

                        page.NavigationCacheMode = NavigationCacheMode.Required;                         // TODO: Investigate why we need this.
                        viewModel.SetView(page);
                        page.DataContext = viewModel;

                        if (page.IsLoaded || _frame.Visibility == Visibility.Collapsed)
                        {
                            // If the page is loaded, we return it directly.
                            // If the page is not loaded, but the _frame is collapsed, the page will not load, so we don't wait for it to load.
                            page.Loaded -= OnPageLoaded;
                            return(page);
                        }
                        else
                        {
#if __IOS__
                            // The event sequence doesn't seem to work properly on iOS.
                            // The Loaded event doesn't seem to be raised so we don't wait and simply return the page.
                            page.Loaded -= OnPageLoaded;
                            return(page);
#else
                            // If the _frame is visible and the page is not loaded, we wait for the page to load.
                            return(await viewTcs.Task);
#endif
                        }
                    }
                    else
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError($"Failed frame navigation to view '{viewType.FullName}' because the this type is not a Page.");
                        }

                        throw new InvalidOperationException($"Failed frame navigation to view '{viewType.FullName}' because the this type is not a Page.");
                    }
                }
                catch (NavigationCanceledException e)
                {
                    if (_logger.IsEnabled(LogLevel.Error))
                    {
                        _logger.LogError($"Failed frame navigation to view '{viewType.FullName}' because it was canceled.", e);
                    }

                    throw;
                }
                catch (Exception e)
                {
                    if (_logger.IsEnabled(LogLevel.Error))
                    {
                        _logger.LogError($"Failed frame navigation to view '{viewType.FullName}'.", e);
                    }

                    throw;
                }
            }
        }
Exemplo n.º 12
0
 private void _nodeShutdown(object sender, INavigableViewModel navigableVM)
 {
     _node_shutdown(navigableVM);
 }
Exemplo n.º 13
0
 private void _prevCalled(object sender, INavigableViewModel navigableVM)
 {
     _prev(navigableVM);
 }
Exemplo n.º 14
0
 private void _node_shutdown(INavigableViewModel navigableVM)
 {
     if (navigableVM != null)
     {
         navigableVM.NextCalled -= _nextCalled;
         navigableVM.PreviousCalled -= _prevCalled;
         navigableVM.Shutdown -= _nodeShutdown;
     }
 }
Exemplo n.º 15
0
 public TimeViewModel(INavigableViewModel navigableViewModel)
     : base(navigableViewModel)
 {
     timer = TimerFactory.StartAndExecute(TimeSpan.FromSeconds(1), () => CurrentTime = DateTime.Now);
 }
Exemplo n.º 16
0
        private void _next(INavigableViewModel navigableVM)
        {
            try
            {
                LinkedListNode<INavigableViewModel> currentNode = _navigation.Find(navigableVM);
                if (currentNode.Next != null)
                {
                    currentNode = currentNode.Next;
                    _currentEntities[_currentEntitiesView.CurrentPosition] = currentNode.Value;
                    currentNode.Value.NextCalled += _nextCalled;
                    currentNode.Value.PreviousCalled += _prevCalled;
                    currentNode.Value.Shutdown += _nodeShutdown;
                }
            }
            catch (Exception ex)
            {

                Logger.Log(ex);
            }
        }
Exemplo n.º 17
0
        private void _prev(INavigableViewModel navigableVM)
        {
            try
            {
                LinkedListNode<INavigableViewModel> currentNode = _navigation.Find(navigableVM);
                if (currentNode.Previous != null)
                {
                    currentNode = currentNode.Previous;
                    _currentEntities[_currentEntitiesView.CurrentPosition] = currentNode.Value;
                }
            }
            catch (Exception ex)
            {

                Logger.Log(ex);
            }
        }
Exemplo n.º 18
0
 private void _nextCalled(object sender, INavigableViewModel navigableVM)
 {
     _next(navigableVM);
 }
Exemplo n.º 19
0
 private void _nodeShutdown(object sender, INavigableViewModel navigableVM)
 {
     _node_shutdown(navigableVM);
 }
Exemplo n.º 20
0
 /// <summary>
 /// Creates a new instance of <see cref="NavigationStackEntry"/>.
 /// </summary>
 /// <param name="request">The navigation request.</param>
 /// <param name="viewModel">The ViewModel.</param>
 /// <param name="view">The view.</param>
 public NavigationStackEntry(StackNavigatorRequest request, INavigableViewModel viewModel, object view)
 {
     Request   = request;
     ViewModel = viewModel;
     View      = view;
 }
Exemplo n.º 21
0
 protected NavigableViewModel(INavigableViewModel navigableViewModel)
 {
     this.navigableViewModel = navigableViewModel;
 }
Exemplo n.º 22
0
		public WelcomeViewModel(INavigableViewModel navigableViewModel)
			: base(navigableViewModel)
		{
		}
Exemplo n.º 23
0
 public SettingsViewModel(INavigableViewModel navigableViewModel)
     : base(navigableViewModel)
 {
 }
Exemplo n.º 24
0
 public WelcomeViewModel(INavigableViewModel navigableViewModel)
     : base(navigableViewModel)
 {
 }
Exemplo n.º 25
0
 protected override Task <object> InnerNavigateAndGetView(INavigableViewModel viewModel)
 {
     // Don't do anything.
     return(Task.FromResult <object>(null));
 }
Exemplo n.º 26
0
 private void _nextCalled(object sender, INavigableViewModel navigableVM)
 {
     _next(navigableVM);
 }
Exemplo n.º 27
0
 public LoginViewModel(INavigableViewModel navigableViewModel)
     : base(navigableViewModel)
 {
 }
Exemplo n.º 28
0
 private void _prevCalled(object sender, INavigableViewModel navigableVM)
 {
     _prev(navigableVM);
 }