protected override async void OnNavigatedTo(NavigationEventArgs e) { if (!previouslyLoaded) { var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/InkRecognitionSampleInstructions.gif")); if (file != null) { using (var stream = await file.OpenSequentialReadAsync()) { await inkCanvas.InkPresenter.StrokeContainer.LoadAsync(stream); } } previouslyLoaded = true; } // When the page is Unloaded, the Win2D CanvasControl is disposed. To preserve the state of the page we need to re-instantiate this object. // In the case of the Win2D CanvasControl, a new UI Element needs to be created/appended to the page as well var resultCanvas = new CanvasControl(); resultCanvas.Name = "resultCanvas"; resultCanvas.Draw += ResultCanvas_Draw; resultCanvas.SetValue(Grid.ColumnSpanProperty, 2); resultCanvas.SetValue(Grid.RowProperty, 2); resultCanvasGrid.Children.Add(resultCanvas); RecognizeButton_Click(null, null); base.OnNavigatedTo(e); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { if (!previouslyLoaded) { var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/InkRecognizerSampleInstructions.gif")); if (file != null) { using (var stream = await file.OpenSequentialReadAsync()) { await inkCanvas.InkPresenter.StrokeContainer.LoadAsync(stream); } } previouslyLoaded = true; } // When the page is Unloaded, InkRecognizer and the Win2D CanvasControl are disposed. To preserve the state of the page we need to re-instantiate these objects. // In the case of the Win2D CanvasControl, a new UI Element needs to be created/appended to the page as well string endpoint = localSettings.Values["InkRecognizerEndpoint"] as string; string apiKey = localSettings.Values["InkRecognizerApiKey"] as string; if (string.IsNullOrEmpty(endpoint) || !Uri.IsWellFormedUriString(endpoint, UriKind.Absolute)) { await new MessageDialog("Ensure you have a valid URI set in the Settings page.", "Invalid or Missing URI").ShowAsync(); } else { inkRecognizer = new InkRecognizer(endpoint, apiKey); } var resultCanvas = new CanvasControl(); resultCanvas.Name = "resultCanvas"; resultCanvas.Draw += ResultCanvas_Draw; resultCanvas.SetValue(Grid.RowProperty, 0); resultCanvasGrid.Children.Add(resultCanvas); base.OnNavigatedTo(e); }