コード例 #1
0
        // When an item in the list of SVG files is selected, show it in the preview WebView.
        private async void SVGlistView_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                Debug.Assert(e.ClickedItem is SvgFileItem);
                SvgFileItem selectedItem = e.ClickedItem as SvgFileItem;

                // Set the source of the preview Image to the SVG file.
                SVGPreviewImage.Source = new SvgImageSource(new Uri("ms-appdata:///temp/preview/" + selectedItem.FileName));

                selectedSvgItems.Clear();
                selectedSvgItems.Add(selectedItem);
            }
            catch (Exception exc)
            {
                await NotifyUserAsync("The app encountered an error while trying to preview the selected SVG file.", exc);

                return;
            }

            // Hide hint text and reveal the preview.
            SvgPreviewHintWrapper.Visibility = Visibility.Collapsed;
            SvgPreviewWrapper.Visibility     = Visibility.Visible;
        }
コード例 #2
0
        // When an item in the list of SVG files is selected, show it in the preview WebView.
        private async void SVGlistView_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                Debug.Assert(e.ClickedItem is SvgFileItem);
                SvgFileItem selectedItem = e.ClickedItem as SvgFileItem;

                // Plug in the name of the SVG file to render.
                string placeHolderHTML = System.IO.File.ReadAllText("HTML.html");
                string totalHTML       = placeHolderHTML.Replace("PlaceHolder", selectedItem.FileName);

                selectedSvgItems.Clear();
                selectedSvgItems.Add(selectedItem);

                // Write prepared HTML to temp  preview folder.
                StorageFile htmlFile = await svgPreviewTempFolder.CreateFileAsync("Preview.html", CreationCollisionOption.ReplaceExisting);

                await FileIO.WriteTextAsync(htmlFile, totalHTML);

                await htmlFile.CopyAsync(svgPreviewTempFolder, "SVGPreview.html", NameCollisionOption.ReplaceExisting);

                // Navigate WebView to preview HTML page.
                Uri source = new Uri("ms-appdata:///temp/preview/SVGPreview.html");
                SVGPreview.Navigate(source);
            }
            catch (Exception exc)
            {
                await NotifyUserAsync("The app encountered an error while trying to preview the selected SVG file.", exc);

                return;
            }

            // Hide hint text and reveal the preview.
            SvgPreviewHintWrapper.Visibility = Visibility.Collapsed;
            SvgPreviewWrapper.Visibility     = Visibility.Visible;
        }