/// <summary> /// This is the click handler for the 'Execute' button. /// When this button is activated, the text suggestion generator will get /// the reverse conversion result for given input string and language tag, then /// print them in result column. /// Using 'async' keyword to indicate that this method runs asynchronously /// and contains one 'await' expression. /// </summary> /// <param name="sender">The object that raised the event.</param> /// <param name="e">Event data that describes the click action on the button.</param> private async void Execute_Click(object sender, RoutedEventArgs e) { // Clean up result column. resultView.ItemsSource = null; // Clean notification area. rootPage.NotifyUser(string.Empty, NotifyType.StatusMessage); var input = Input.Text; ComboBoxItem selectedItem = methods.SelectedItem as ComboBoxItem; if ((generator != null) && (selectedItem != null) && (!String.IsNullOrEmpty(input))) { if ((selectedItem.Tag != null) && selectedItem.Tag.ToString().Equals("segmented")) { // Get the reverse conversion result per phoneme through calling the API and print it in result area. // Using 'await' expression here to suspend the execution of this method until the awaited task completes. IReadOnlyList <TextPhoneme> phonemes = await generator.GetPhonemesAsync(input); List <string> results = new List <string>(); foreach (TextPhoneme phoneme in phonemes) { results.Add(string.Format("{0} -> {1}", phoneme.DisplayText, phoneme.ReadingText)); } resultView.ItemsSource = results; if (phonemes.Count == 0) { rootPage.NotifyUser(string.Format("No results"), NotifyType.StatusMessage); } } else { // Get the reverse conversion result through calling the API and print it in result area. // Using 'await' expression here to suspend the execution of this method until the awaited task completes. string result = await generator.ConvertBackAsync(input); resultView.ItemsSource = new List <string> { result }; if (result.Length == 0) { rootPage.NotifyUser(string.Format("No results"), NotifyType.StatusMessage); } } } }
/// <summary> /// This is the click handler for the 'Execute' button. /// When this button is activated, the text suggestion generator will get /// the reverse conversion result for given input string and language tag, then /// print them in result column. /// Using 'async' keyword to indicate that this method runs asynchronously /// and contains one 'await' expression. /// </summary> /// <param name="sender">The object that raised the event.</param> /// <param name="e">Event data that describes the click action on the button.</param> private async void Execute_Click(object sender, RoutedEventArgs e) { // Clean up result column. result.Text = string.Empty; // Clean notification area. rootPage.NotifyUser(string.Empty, NotifyType.StatusMessage); var input = Input.Text; ComboBoxItem selectedItem = methods.SelectedItem as ComboBoxItem; if ((generator != null) && (selectedItem != null) && (!String.IsNullOrEmpty(input))) { // Get the reverse conversion result through calling the API and print it in result area. // Using 'await' expression here to suspend the execution of this method until the awaited task completes. result.Text = await generator.ConvertBackAsync(input); if (result.Text.Length == 0) { rootPage.NotifyUser(string.Format("No candidates"), NotifyType.StatusMessage); } } }