private async void save_Click(object sender, RoutedEventArgs e)
        {
            StorageFile myStorageFile = await MyFilePicker.LetUserPickFile2Save();

            if (myStorageFile != null)
            {
                save_DoIt(myStorageFile);

                DoNextStage();
            }
        }
Example #2
0
        /// <summary>
        /// Get the track that was chosen and paint that
        /// </summary>
        /// <param name="e"></param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            // first paint the track
            int?trackNumber = e.Parameter as int?;

            if (trackNumber != null)
            {
                try
                {
                    if (trackNumber != LOAD_TRACK_NR)
                    {
                        // a predefined track was chosen, get this track
                        mActiveTrack = TrackProvider.GetTrack((uint)trackNumber);
                    }
                    else
                    {
                        // user chose "Load Track"
                        // FileBrowseDialog
                        string filePath = await MyFilePicker.LetUserPickFile2Open();

                        if (filePath != null)
                        {
                            try
                            {
                                // load track
                                mActiveTrack = await TrackLoader.LoadTrack(filePath);
                            }
                            catch (Exception)
                            {
                                MessageDialog dialog = new MessageDialog("Please choose another track file, because the selected file is invalid: "
                                                                         + Environment.NewLine + "'" + filePath + "'.", "Error");
                                await dialog.ShowAsync();

                                // an exception occurred, return to main page
                                Back2Main();
                            }
                        }
                    }

                    if (mActiveTrack != null)
                    {
                        mActiveTrack.PaintTrack(xMyCanvas.Children, xMyCanvas.Width, xMyCanvas.Height,
                                                GridLinePainter.GetMiddleGridRowYCoordinate(xMyCanvas));

                        // highscore
                        SetHighscoreInGUI();

                        InitRace();
                    }
                    else
                    {
                        // loading track failed, navigate back to main
                        Back2Main();
                    }
                }
                catch (Exception)
                {
                    MessageDialog dialog = new MessageDialog("Problem with loading the track", "Error");
                    await dialog.ShowAsync();

                    // an exception occurred, return to main page
                    Back2Main();
                }
            }
        }