public override async void OnNavigatedTo(object navigationParameter, Windows.UI.Xaml.Navigation.NavigationMode navigationMode, Dictionary <string, object> viewModelState)
 {
     if (navigationParameter != null)
     {
         base.OnNavigatedTo(navigationParameter, navigationMode, viewModelState);
     }
 }
        public async override void OnNavigatedTo(object navigationParameter, Windows.UI.Xaml.Navigation.NavigationMode navigationMode, Dictionary <string, object> viewModelState)
        {
            base.OnNavigatedTo(navigationParameter, navigationMode, viewModelState);

            if (viewModelState != null)
            {
                if (navigationMode == NavigationMode.Refresh)
                {
                    var personErrorsCollection = RetrieveEntityStateValue <IDictionary <string, ReadOnlyCollection <string> > >("personErrorsCollection", viewModelState);
                    if (personErrorsCollection != null)
                    {
                        SelectedPerson.SetAllErrors(personErrorsCollection);
                    }
                }
            }

            // Note: Each time app selects from main page (PersonListPage) detail page (PersonDetailPage) is recreated.
            // Meaning that constructor is run and SelectedPerson is null.
            // If SuspendAndTerminate (e.g. debug mode) SelectedPerson is saved to SessionState (because of [RestorableState] attribute).
            // Therefore, if SelectedPerson has been saved, use it instead of doing GetPersonAsync.
            if (SelectedPerson == null)
            {
                string errorMessage = string.Empty;
                int    personId     = (int)navigationParameter;

                if (personId == 0)
                {
                    SelectedPerson = new Person();
                    SelectedPerson.ValidateProperties();
                    RunAllCanExecute();
                }
                else
                {
                    try {
                        LoadingData = true;
                        CrudResult  = await _personRepository.GetPersonAsync(personId);

                        SelectedPerson = JsonConvert.DeserializeObject <List <Person> >(CrudResult.Content.ToString()).FirstOrDefault <Person>();
                    }
                    catch (HttpRequestException ex) {
                        ErrorMessageTitle = ErrorMessagesHelper.HttpRequestExceptionError;
                        //TODO: Log stack trace to database here
                        ErrorMessage = string.Format("{0}", ex.Message);
                    }
                    finally {
                        LoadingData = false;
                    }
                    if (ErrorMessage != null && ErrorMessage != string.Empty)
                    {
                        MessageDialog messageDialog = new MessageDialog(ErrorMessage, ErrorMessageTitle);
                        await messageDialog.ShowAsync();

                        _navService.GoBack();
                    }
                }
            }

            RunAllCanExecute();
        }
Exemplo n.º 3
0
        public override async void OnNavigatedTo(object navigationParameter, Windows.UI.Xaml.Navigation.NavigationMode navigationMode, Dictionary <string, object> viewModelState)
        {
            /*
             * if (viewModelState == null) return;
             *
             * if (navigationMode == NavigationMode.New)
             * {
             *  viewModelState["ReserveringViewModel"] = new Dictionary<string, object>();
             * }
             *
             * ReserveringViewModel.OnNavigatedTo(navigationParameter, navigationMode, viewModelState["ReserveringViewModel"] as Dictionary<string, object>);
             */
            /*
             * _vereniging = await _verenigingRepository.GetVerenigingAsync();
             * _reservering = await _reserveringRepository.GetReserveringAsync();
             *
             * SpelerViewModels = new ObservableCollection<SpelerViewModel>();
             *
             * Speler emptySpeler = new Speler { Id = Guid.Empty };
             * for (int i = 0; i < 4; i++)
             * {
             *  Speler speler = emptySpeler;
             *  try
             *  {
             *      if (_reservering.Spelers.Count >= i + 1)
             *          speler = _reservering.Spelers[i];
             *
             *  }
             *  catch
             *  {
             *      speler = emptySpeler;
             *  }
             *
             *  var spelerViewModel = new SpelerViewModel(i, speler, _spelerRepository, _reserveringRepository,_verenigingRepository, _navigationService, _resourceLoader, _alertMessageService, _eventAggregator);
             *  SpelerViewModels.Insert(i, spelerViewModel);
             *
             *  //SpelerViewModels[i] = spelerViewModel;
             *  //OnPropertyChanged("Spelers");
             *
             * }
             */
            /*
             * foreach (Speler speler in _reservering.Spelers)
             * {
             *  Spelers.Add(new SpelerViewModel(speler, _spelerRepository, _reserveringRepository, _navigationService, _resourceLoader, _alertMessageService, _eventAggregator));
             * }
             */

            if (navigationParameter != null)
            {
                base.OnNavigatedTo(navigationParameter, navigationMode, viewModelState);
            }
        }
Exemplo n.º 4
0
        private Core.Helpers.NavigationMode FromNativeNavigationMode(Windows.UI.Xaml.Navigation.NavigationMode nativeMode)
        {
            switch (nativeMode)
            {
            case Windows.UI.Xaml.Navigation.NavigationMode.Back: return(Core.Helpers.NavigationMode.Back);

            case Windows.UI.Xaml.Navigation.NavigationMode.Forward: return(Core.Helpers.NavigationMode.Forward);

            case Windows.UI.Xaml.Navigation.NavigationMode.New: return(Core.Helpers.NavigationMode.New);

            case Windows.UI.Xaml.Navigation.NavigationMode.Refresh: return(Core.Helpers.NavigationMode.Refresh);

            default: return(Core.Helpers.NavigationMode.Refresh);
            }
        }
Exemplo n.º 5
0
        public static Portable.NavigationMode ToTemplate10NavigationMode(this UWP.NavigationMode mode)
        {
            switch (mode)
            {
            case UWP.NavigationMode.New: return(Portable.NavigationMode.New);

            case UWP.NavigationMode.Back: return(Portable.NavigationMode.Back);

            case UWP.NavigationMode.Forward: return(Portable.NavigationMode.Forward);

            case UWP.NavigationMode.Refresh: return(Portable.NavigationMode.Refresh);

            default:
                throw new NotSupportedException();
            }
        }
Exemplo n.º 6
0
        public override void NavigatedTo(Windows.UI.Xaml.Navigation.NavigationMode mode, object parameter)
        {
            base.NavigatedTo(mode, parameter);

            var id = parameter as int?;

            if (id == null)
            {
                return;
            }

            HardwareButtons.BackPressed += HardwareButtonsOnBackPressed;

            var msg = new GenericMessage <int>((int)id);

            Messenger.Default.Send(msg, "playlist-coll-detail-id");
        }
Exemplo n.º 7
0
        static NavigationType Translate(Windows.UI.Xaml.Navigation.NavigationMode mode)
        {
            switch (mode)
            {
            case Windows.UI.Xaml.Navigation.NavigationMode.Back:
                return(NavigationType.Back);

            case Windows.UI.Xaml.Navigation.NavigationMode.Forward:
                return(NavigationType.Forward);

            case Windows.UI.Xaml.Navigation.NavigationMode.New:
                return(NavigationType.New);

            case Windows.UI.Xaml.Navigation.NavigationMode.Refresh:
                return(NavigationType.Refresh);
            }

            return(NavigationType.Unknown);
        }
Exemplo n.º 8
0
        private async Task <bool> CanChangePage(Type requestingViewModel, XamlNav.NavigationMode navigationMode, NavigationType navigationType)
        {
            // We will do this for the UWP only interface INavigable
            var navigableViewModel = this.ContentDataContext as INavigable;

            if (navigableViewModel != null)
            {
                var args = new NavigatingInfo(navigationMode, navigationType, requestingViewModel);
                await navigableViewModel.OnNavigatingFrom(args);

                return(!args.Cancel);
            }

            // And also for the interface that also exist for desktop for compatibility reasons
            var frameAware = this.ContentDataContext as IFrameAware;

            if (frameAware != null)
            {
                return(frameAware.CanClose());
            }

            return(true);
        }
Exemplo n.º 9
0
        internal async Task <bool> Navigate(Type viewModelType, object[] arguments, XamlNav.NavigationMode navigationMode, NavigationType navigationType)
        {
            if (!await this.CanChangePage(viewModelType, navigationMode, navigationType))
            {
                return(false);
            }

            FrameworkElement view      = null;
            IViewModel       viewModel = null;

            // Create a view
            if (navigationMode == XamlNav.NavigationMode.Back || navigationMode == XamlNav.NavigationMode.Forward || navigationMode == XamlNav.NavigationMode.New)
            {
                view = GetView(viewModelType);
            }

            // Create a view model
            if (navigationMode == XamlNav.NavigationMode.Back || navigationMode == XamlNav.NavigationMode.Forward || navigationMode == XamlNav.NavigationMode.Refresh)
            {
                viewModel = Factory.Create(viewModelType, arguments).As <IViewModel>(); // Use Factory create here so that the factory extensions are invoked
            }
            // Bind the IsLoading if implemented
            if (view != null)
            {
                view.SetBinding(Control.IsEnabledProperty, new Binding
                {
                    Path      = new PropertyPath(nameof(IViewModel.IsLoading)),
                    Converter = new BooleanInvertConverter()
                });
            }

            if (navigationMode == XamlNav.NavigationMode.Back || navigationMode == XamlNav.NavigationMode.Forward)
            {
                // Setup the page transition animations
                if (view.Transitions != null && view.Transitions.Count > 0)
                {
                    this.ContentTransitions = view.Transitions;
                }
                else
                {
                    this.ContentTransitions = this.DefaultChildrenTransitions;
                }

                // we need to keep our old datacontext to dispose them properly later on
                var oldDataContext = this.ContentDataContext;
                var oldView        = this.Content.As <FrameworkElement>();
                // Assign our new content
                this.Content = view;
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => view.DataContext = viewModel);

                // Invoke the Navigation stuff in the current datacontext
                await AsyncHelper.NullGuard(viewModel.As <INavigable>()?.OnNavigatedTo(new NavigationInfo(navigationMode, navigationType, oldDataContext?.GetType())));

                // Remove the reference of the old vm from the old view
                oldView.IsNotNull(x => x.DataContext = null);
                // Now invoke the navigated from on our old data context
                await AsyncHelper.NullGuard(oldDataContext?.As <INavigable>()?.OnNavigatedFrom(new NavigationInfo(navigationMode, navigationType, viewModelType)));

                // dispose the old viewmodel
                oldDataContext?.TryDispose();
            }
            else if (navigationMode == XamlNav.NavigationMode.New)
            {
                // NavigationMode.New means recreate the view but preserve the viewmodel
                // we need to keep our current datacontext for later reassigning
                var currentDataContext = this.ContentDataContext;
                var oldView            = this.Content.As <FrameworkElement>();

                // cancel this if the oldview and the new view are the same
                if (oldView.GetType() == view.GetType())
                {
                    return(false);
                }

                // Assign our content
                this.Content = view;
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => view.DataContext = currentDataContext);

                // Invoke the Navigation stuff in the current datacontext
                await AsyncHelper.NullGuard(currentDataContext.As <INavigable>()?.OnNavigatedTo(new NavigationInfo(navigationMode, navigationType, currentDataContext.GetType())));

                // Remove the reference of the current viewmodel from the old view
                oldView.IsNotNull(x => x.DataContext = null);
            }
            else if (navigationMode == XamlNav.NavigationMode.Refresh)
            {
                // we need to keep our old datacontext to dispose them properly later on
                var oldDataContext = this.ContentDataContext;
                // NavigationMode.Refresh means recreate the view model but preserve the view
                viewModel = Factory.Create(viewModelType, arguments).As <IViewModel>();
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => view.DataContext = viewModel);

                // Invoke the Navigation stuff in the current datacontext
                await AsyncHelper.NullGuard(viewModel.As <INavigable>()?.OnNavigatedTo(new NavigationInfo(navigationMode, navigationType, viewModelType)));

                // dispose the old viewmodel
                oldDataContext?.TryDispose();
            }

            // Refresh the stacks
            if (navigationMode == XamlNav.NavigationMode.Forward)
            {
                // we have to check if the current viewmodel is the same as the one the top of the forwardstack
                // if that is the case we remove it from the stack
                // if that is not the case, then we clear the stack
                if (this.ForwardStack.Count > 0)
                {
                    var stackEntry = this.ForwardStack[0];

                    // Remove the stack if equal
                    if (viewModelType == stackEntry.ViewModelType &&
                        ((stackEntry.Parameters != null && arguments != null && stackEntry.Parameters.SequenceEqual(arguments)) ||
                         (stackEntry.Parameters == null && arguments == null)))
                    {
                        this.ForwardStack.RemoveAt(0);
                    }
                    else
                    {
                        this.ForwardStack.Clear();
                    }
                }
            }

            if (navigationMode == XamlNav.NavigationMode.Back || navigationMode == XamlNav.NavigationMode.Forward)
            {
                this.BackStack.Add(new PageStackEntry(viewModelType, arguments));
            }

            // remove entries from stack
            if (this.MaxStackSize > 1)
            {
                if (this.BackStack.Count > this.MaxStackSize + 1)
                {
                    this.BackStack.RemoveAt(0);
                }

                if (this.ForwardStack.Count > this.MaxStackSize)
                {
                    this.ForwardStack.RemoveAt(this.ForwardStack.Count - 1);
                }
            }

            this.CanGoBack    = this.BackStack.Count > 1;
            this.CanGoForward = this.ForwardStack.Count > 0;

            this.Navigated?.Invoke(this, EventArgs.Empty);
            return(true);
        }
Exemplo n.º 10
0
 public override void NavigatedTo(Windows.UI.Xaml.Navigation.NavigationMode mode, object parameter)
 {
     base.NavigatedTo(mode, parameter);
     BackgroundAnimation.Begin();
 }
Exemplo n.º 11
0
 public override void OnNavigatedTo(object navigationParameter, Windows.UI.Xaml.Navigation.NavigationMode navigationMode, Dictionary <string, object> viewModelState)
 {
     PictureSearch.SearchAction = new Action <string>(LoadPictures);
     LoadPictures();
 }