コード例 #1
0
ファイル: MainViewModel.cs プロジェクト: rrsc/uwp
        /// <summary>
        /// Initialize the viewmodel
        /// </summary>
        /// <param name="navActionType">Navigation action used to arrive to the MainPage</param>
        public void Initialize(NavigationActionType navActionType = NavigationActionType.Default)
        {
            // Set the navigation action used to arrive to the MainPage
            this.NavActionType = navActionType;

            // Set the default menu item to home/first item
            this.SelectedItem = this.MenuItems.FirstOrDefault();
        }
コード例 #2
0
 /// <summary>
 /// Create a NavigationObject
 /// </summary>
 /// <param name="sourceViewModel">Type of viewmodel that initiaties the navigation</param>
 /// <param name="action">Type of navigation action</param>
 /// <param name="parameters">Navigation parameters</param>
 /// <returns>Navigation object</returns>
 public static NavigationObject Create(Type sourceViewModel,
                                       NavigationActionType action = NavigationActionType.Default,
                                       IDictionary <NavigationParamType, object> parameters = null)
 {
     return(new NavigationObject
     {
         SourceViewModel = sourceViewModel,
         Action = action,
         Parameters = parameters == null
             ? new Dictionary <NavigationParamType, object>()
             : new Dictionary <NavigationParamType, object>(parameters)
     });
 }
コード例 #3
0
        /// <summary>
        /// Navigate to page that holds the specified viewmodel type
        /// </summary>
        /// <param name="viewModelType">Type of viewmodel to navigate to</param>
        /// <param name="action">Optional navigation action parameter</param>
        /// <param name="parameters">Optional navigation data parameters</param>
        public void NavigateTo(Type viewModelType,
                               NavigationActionType action = NavigationActionType.Default,
                               IDictionary <NavigationParamType, object> parameters = null)
        {
            if (viewModelType == null)
            {
                throw new ArgumentNullException(nameof(viewModelType));
            }

            var pageType = NavigateService.GetViewType(viewModelType);

            if (pageType == null)
            {
                throw new ArgumentException("Viewmodel is not bound to a view");
            }

            var navObj = NavigationObject.Create(this.GetType(), action, parameters);

            OnUiThread(() => this.Navigation.Navigate(pageType, false, navObj));
        }
コード例 #4
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // Do not allow user to go back to any previous page
            NavigateService.CoreFrame.BackStack.Clear();
            AppService.SetAppViewBackButtonVisibility(false);

            // If exists a navigation object
            if (e?.Parameter != null)
            {
                var navObj = NavigateService.GetNavigationObject(e.Parameter);
                NavigationActionType navActionType = navObj.Action;

                // Try to avoid display duplicate alerts
                if (isAlertAlreadyDisplayed)
                {
                    return;
                }
                isAlertAlreadyDisplayed = true;

                switch (navActionType)
                {
                case NavigationActionType.Login:
                    this.ViewModel.LoginViewModel.Email = navObj.Parameters[NavigationParamType.Email] as string;
                    await DialogService.ShowAlertAsync(
                        ResourceService.AppMessages.GetString("AM_AlreadyConfirmedAccount_Title"),
                        ResourceService.AppMessages.GetString("AM_AlreadyConfirmedAccount"));

                    break;

                case NavigationActionType.Recovery:
                    this.ViewModel.LoginViewModel.Email    = navObj.Parameters[NavigationParamType.Email] as string;
                    this.ViewModel.LoginViewModel.Password = navObj.Parameters[NavigationParamType.Password] as string;
                    break;

                case NavigationActionType.API_ESID:
                    // Show a message notifying the error
                    await DialogService.ShowAlertAsync(
                        ResourceService.AppMessages.GetString("AM_SessionIDError_Title"),
                        ResourceService.AppMessages.GetString("AM_SessionIDError"));

                    break;

                case NavigationActionType.API_EBLOCKED:
                    string message;
                    switch ((AccountBlockedReason)navObj.Parameters[NavigationParamType.Number])
                    {
                    case AccountBlockedReason.Copyright:
                        message = ResourceService.AppMessages.GetString("AM_AccountBlockedCopyright");
                        break;

                    case AccountBlockedReason.OtherReason:
                    default:
                        message = ResourceService.AppMessages.GetString("AM_AccountBlocked");
                        break;
                    }

                    // Show a message notifying the error
                    await DialogService.ShowAlertAsync(
                        ResourceService.AppMessages.GetString("AM_AccountBlocked_Title"), message);

                    break;
                }

                isAlertAlreadyDisplayed = false;
            }

            if (DebugService.DebugSettings.IsDebugMode && DebugService.DebugSettings.ShowDebugAlert)
            {
                DialogService.ShowDebugModeAlert();
            }
        }