protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); printHelper = new PhotosPrintHelper(this); printHelper.RegisterForPrinting(); }
/// Open coloring page with coloring image and, if applicable, ink. protected override async void OnNavigatedTo(NavigationEventArgs e) { // NavigationEvent parameter is the source of the coloring page, either a blank coloring image or a previously inked coloring page. String parameter = e.Parameter.ToString(); // If navigating from ContinueColoring, the image is a previously inked coloring page. if (parameter.EndsWith(Constants.inkedImageFile)) { // Get folder in local storage containing ink file and coloring image source. string folderpath = parameter.Substring(0, parameter.IndexOf(Constants.inkedImageFile)); _Foldername = folderpath.Substring(parameter.IndexOf(Constants.inkImageFolder)); try { StorageFolder folder = await ApplicationData.Current.LocalFolder.GetFolderAsync(_Foldername); // Get coloring image source. StorageFile imgsrcFile = await folder.GetFileAsync(Constants.imgsrcFile); _Imgsrc = await FileIO.ReadTextAsync(imgsrcFile); // Load ink. StorageFile inkFile = await folder.GetFileAsync(Constants.inkFile); if (inkFile != null) { IRandomAccessStream stream = await inkFile.OpenAsync(Windows.Storage.FileAccessMode.Read); using (var inputStream = stream.GetInputStreamAt(0)) { await myInkCanvas.InkPresenter.StrokeContainer.LoadAsync(stream); } stream.Dispose(); } } catch (Exception ex) { Debug.WriteLine(ex); } } // If navigating from PickColoringPage, the image is a blank coloring image. else { Uri abspath = new Uri($"{Windows.ApplicationModel.Package.Current.InstalledLocation.Path}\\Images"); Uri relpath = abspath.MakeRelativeUri(new Uri(parameter)); _Imgsrc = relpath.ToString(); } // Set up printing. _PrintHelper = new PhotosPrintHelper(this); _PrintHelper.RegisterForPrinting(); // Adjust ScrollViewer size to Window. var bounds = Window.Current.Bounds; myScrollViewer.Height = bounds.Height - myCommandBar.Height; myScrollViewer.Width = bounds.Width; myImage.Source = new BitmapImage(new Uri("ms-appx:///" + _Imgsrc)); }