public SamplePage()
        {
            InitializeComponent();

            HideStatusBar();

            // Get selected sample and set that as the DataContext.
            DataContext = SampleManager.Current.SelectedSample;

            // Load and show the sample.
            SampleContainer.Content = SampleManager.Current.SampleToControl(SampleManager.Current.SelectedSample);

            // Default to the live sample view.
            LiveSample.IsChecked = true;

            string folderPath    = SampleManager.Current.SelectedSample.Path;
            string cssPath       = "ms-appx-web:///Resources\\github-markdown.css";
            string basePath      = $"ms-appx-web:///{folderPath.Substring(folderPath.LastIndexOf("Samples"))}";
            string readmePath    = System.IO.Path.Combine(folderPath, "Readme.md");
            string readmeContent = System.IO.File.ReadAllText(readmePath);

            readmeContent = _markdownRenderer.Parse(readmeContent);
            readmeContent = readmeContent.Replace("src='", "src=\"").Replace(".jpg'", ".jpg\"").Replace("src=\"", $"src=\"{basePath}\\");
            string htmlString = "<!doctype html><head><link rel=\"stylesheet\" href=\"" + cssPath + "\" /></head><body class=\"markdown-body\">" + readmeContent + "</body>";

            DescriptionView.NavigateToString(htmlString);
            SourceCodeContainer.LoadSourceCode();
        }
Пример #2
0
        public SamplePage()
        {
            InitializeComponent();

            // Add events for cleaning up sample page when closed or opened.
            Unloaded += SamplePage_Unloaded;
            Loaded   += SamplePage_Loaded;

            // Get selected sample and set that as the DataContext.
            DataContext = SampleManager.Current.SelectedSample;

            // Load and show the sample.
            SampleContainer.Content = SampleManager.Current.SampleToControl(SampleManager.Current.SelectedSample);

            // Change UI elements to be dark.
            if (App.Current.RequestedTheme == ApplicationTheme.Dark)
            {
                DescriptionBlock.RequestedTheme = ElementTheme.Dark;
            }

            // Set file path for the readme.
            string readmePath = System.IO.Path.Combine(SampleManager.Current.SelectedSample.Path, "Readme.md");
            string readmeText = System.IO.File.ReadAllText(readmePath);

            // Take off first line (the title header)
            readmeText = readmeText.Substring(readmeText.IndexOf('\n') + 1);

            // Fix image links from the old readme format.
            readmeText = readmeText.Replace("<img src=\"", "![](").Replace("\" width=\"350\"/>", ")");

            // Set readme in the mark down block.
            DescriptionBlock.Text = readmeText;

            // Remove the background from the mark down renderer.
            DescriptionBlock.Background = new SolidColorBrush()
            {
                Opacity = 0
            };

            // Set the appropriate backgrounds.
            ContentArea.RequestedTheme      = SampleContainer.RequestedTheme;
            ContentArea.Background          = Tabs.Background;
            DescriptionContainer.Background = (Brush)Application.Current.Resources["ApplicationPageBackgroundThemeBrush"];

            // Load the source code files.
            SourceCodeContainer.LoadSourceCode();
        }
        private async Task SelectSample(SampleInfo selectedSample)
        {
            if (selectedSample == null)
            {
                return;
            }

            SampleTitleBlock.Text = selectedSample.SampleName;
            SampleManager.Current.SelectedSample = selectedSample;
            DescriptionContainer.SetSample(selectedSample);
            ShowSampleTab();

            // Call a function to clear any existing credentials from AuthenticationManager
            ClearCredentials();

            try
            {
                if (selectedSample.OfflineDataItems != null)
                {
                    CancellationTokenSource cancellationSource = new CancellationTokenSource();

                    // Show waiting page
                    SampleContainer.Content = new WPF.Viewer.WaitPage(cancellationSource);

                    // Wait for offline data to complete
                    await DataManager.EnsureSampleDataPresent(selectedSample, cancellationSource.Token);
                }

                // Show the sample
                SampleContainer.Content = SampleManager.Current.SampleToControl(selectedSample);
                SourceCodeContainer.LoadSourceCode();
            }
            catch (OperationCanceledException)
            {
                CategoriesRegion.Visibility = Visibility.Visible;
                SampleContainer.Visibility  = Visibility.Collapsed;
                return;
            }
            catch (Exception exception)
            {
                // failed to create new instance of the sample
                SampleContainer.Content = new WPF.Viewer.ErrorPage(exception);
            }

            CategoriesRegion.Visibility = Visibility.Collapsed;
            SampleContainer.Visibility  = Visibility.Visible;
        }
Пример #4
0
        public SamplePage()
        {
            InitializeComponent();

            HideStatusBar();

            // Get selected sample and set that as the DataContext.
            DataContext = SampleManager.Current.SelectedSample;

            // Load and show the sample.
            SampleContainer.Content = SampleManager.Current.SampleToControl(SampleManager.Current.SelectedSample);

            // Default to the live sample view.
            LiveSample.IsChecked = true;

            SourceCodeContainer.LoadSourceCode();
        }
        private async Task SelectSample(SampleInfo selectedSample)
        {
            if (selectedSample == null)
            {
                return;
            }

            // The following code removes the API key when using the Create and save map sample.
            if (nameof(SampleManager.Current.SelectedSample) != nameof(selectedSample))
            {
                // Remove API key if opening Create and save map sample.
                if (selectedSample.FormalName == "AuthorMap")
                {
                    ApiKeyManager.DisableKey();
                }
                // Restore API key if leaving Create and save map sample.
                else if (SampleManager.Current?.SelectedSample?.FormalName == "AuthorMap")
                {
                    ApiKeyManager.EnableKey();
                }
            }

            SampleTitleBlock.Text = selectedSample.SampleName;
            SampleManager.Current.SelectedSample = selectedSample;
            DescriptionContainer.SetSample(selectedSample);
            ShowSampleTab();

            // Call a function to clear any existing credentials from AuthenticationManager
            ClearCredentials();

            try
            {
                if (selectedSample.OfflineDataItems != null)
                {
                    CancellationTokenSource cancellationSource = new CancellationTokenSource();

                    // Show waiting page
                    SampleContainer.Content = new WPF.Viewer.WaitPage(cancellationSource);

                    // Wait for offline data to complete
                    await DataManager.EnsureSampleDataPresent(selectedSample, cancellationSource.Token);
                }

                // Show the sample
                SampleContainer.Content = SampleManager.Current.SampleToControl(selectedSample);
                SourceCodeContainer.LoadSourceCode();
            }
            catch (OperationCanceledException)
            {
                CategoriesRegion.Visibility = Visibility.Visible;
                SampleContainer.Visibility  = Visibility.Collapsed;
                return;
            }
            catch (Exception exception)
            {
                // failed to create new instance of the sample
                SampleContainer.Content = new WPF.Viewer.ErrorPage(exception);
            }

            CategoriesRegion.Visibility = Visibility.Collapsed;
            SampleContainer.Visibility  = Visibility.Visible;
        }