void _translator_TranslationComplete(object sender, TranslationCompleteEventArgs e) { Deployment.Current.Dispatcher.BeginInvoke(() => { TranslationModel result = new TranslationModel(); result.SourceText = e.OriginalText; result.SourceLanguage = e.FromLanguage; result.TargetLanguage = e.ToLanguage; result.TargetText = e.Translation; if (_isTranslatingFirstText) { result.FirstText = result.SourceText; result.SecondText = result.TargetText; result.IsFirstLanguage = true; } else { result.FirstText = result.TargetText; result.SecondText = result.SourceText; result.IsFirstLanguage = false; } if (_conversation1 == null) { _conversation1 = new ObservableCollection<TranslationModel>(); _conversation2 = new ObservableCollection<TranslationModel>(); secondLangDisplay.ItemsSource = _conversation2; firstLangDisplay.ItemsSource = _conversation1; } _conversation1.Add(result); _conversation2.Add(result); translatingWait.Visibility = Visibility.Collapsed; waitProgressBar.IsIndeterminate = false; }); }
private async void acceptText(object sender, EventArgs e) { // Send to translator HideConfirmation.Begin(); translatingWait.Visibility = Visibility.Visible; waitProgressBar.IsIndeterminate = true; TranslationModel result = new TranslationModel(); result.SourceText = firstConfirmBox.Text; result.SourceLanguage = _selectedFirstLanguage.CodeForTranslator; result.TargetLanguage = _selectedSecondLanguage.CodeForTranslator; if (_isTranslatingFirstText) result.TargetText = await _translator.Translate(firstConfirmBox.Text, _selectedFirstLanguage.CodeForTranslator, _selectedSecondLanguage.CodeForTranslator); else result.TargetText = await _translator.Translate(firstConfirmBox.Text, _selectedSecondLanguage.CodeForTranslator, _selectedFirstLanguage.CodeForTranslator); translatingWait.Visibility = Visibility.Collapsed; waitProgressBar.IsIndeterminate = false; if (_isTranslatingFirstText) { result.FirstText = result.SourceText; result.SecondText = result.TargetText; result.IsFirstLanguage = true; } else { result.FirstText = result.TargetText; result.SecondText = result.SourceText; result.IsFirstLanguage = false; } if (_conversation1 == null) { _conversation1 = new ObservableCollection<TranslationModel>(); _conversation2 = new ObservableCollection<TranslationModel>(); secondLangDisplay.ItemsSource = _conversation2; firstLangDisplay.ItemsSource = _conversation1; } _conversation1.Add(result); _conversation2.Add(result); CreateMicAppBar(); }