public async void fdViewer_MouseUp(object sender, MouseButtonEventArgs e) { var fdViewer = (FlowDocumentScrollViewer)sender; if (fdViewer.Selection != null) { var selectionStart = fdViewer.Selection.Start; var selectionEnd = fdViewer.Selection.End; var selection = new TextRange(selectionStart, selectionEnd).Text; if (selection.Length > 0) { CancellationTokenSource cts = new CancellationTokenSource(); var tabIndex = selection.IndexOf('\t'); if (tabIndex != -1) { selection = selection.Substring(tabIndex + 1); } popupResults = await engine.SearchExact(cts.Token, selection); popupNumberOfEntries = popupResults.Count(); if (popupNumberOfEntries > 0) { popupIndex = 0; popupNext.Visibility = popupPrev.Visibility = (Visibility)(new BooleanToVisibilityConverter().Convert(popupNumberOfEntries > 1, null, null, null)); popupPrev.IsEnabled = false; popupViewer.Document = DictionaryRenderer.Render(popupResults.First(), engine, true); popup.IsOpen = true; ScrollPopupToTop(); } } //var pos = e.GetPosition(fdViewer); } }
private void popupNext_Click(object sender, RoutedEventArgs e) { if (popupIndex + 1 < popupNumberOfEntries) { popupIndex++; popupViewer.Document = DictionaryRenderer.Render(popupResults.ElementAt(popupIndex), engine); ScrollPopupToTop(); if (popupIndex + 1 == popupNumberOfEntries) { popupNext.IsEnabled = false; } popupPrev.IsEnabled = true; } }