private void ShowInsertHyperlinkDialog() { var dialog = new C1HyperlinkDialog { Text = rtb.Selection.Text }; window = new Window(); window.Content = dialog; window.ShowInTaskbar = false; window.WindowStartupLocation = WindowStartupLocation.CenterOwner; window.SizeToContent = SizeToContent.WidthAndHeight; window.WindowStyle = WindowStyle.ToolWindow; var elementSource = HwndSource.FromVisual(rtb) as HwndSource; if (elementSource != null) { int GA_ROOT = 2; IntPtr root = GetAncestor(elementSource.Handle, GA_ROOT); new WindowInteropHelper(window).Owner = root; } window.Closed += delegate { rtb.Focus(); }; dialog.Completed += delegate { window.Close(); if (string.IsNullOrEmpty(dialog.Text) || string.IsNullOrEmpty(dialog.Url)) return; Uri uri = null; try { uri = new Uri(dialog.Url, UriKind.Absolute); } catch (UriFormatException) { try { uri = new Uri("http://" + dialog.Url, UriKind.Absolute); } catch (UriFormatException) { return; } } using (new DocumentHistoryGroup(rtb.DocumentHistory)) { if (rtb.Selection.Text != dialog.Text) { rtb.Selection.Delete(); var run = new C1Run { Text = dialog.Text }; rtb.Selection.Start.InsertInline(run); run.ContentRange.MakeHyperlink(uri, dialog.TargetName); rtb.Selection = run.ContentRange; } else { rtb.Selection.MakeHyperlink(uri, dialog.TargetName); } } rtb.Focus(); }; window.ShowDialog(); }
private void ShowInsertHyperlinkDialog() { var dialog = new C1HyperlinkDialog { Text = rtb.Selection.Text }; window = new Window(); window.Content = dialog; window.ShowInTaskbar = false; window.WindowStartupLocation = WindowStartupLocation.CenterOwner; window.SizeToContent = SizeToContent.WidthAndHeight; window.WindowStyle = WindowStyle.ToolWindow; var elementSource = HwndSource.FromVisual(rtb) as HwndSource; if (elementSource != null) { int GA_ROOT = 2; IntPtr root = GetAncestor(elementSource.Handle, GA_ROOT); new WindowInteropHelper(window).Owner = root; } window.Closed += delegate { rtb.Focus(); }; dialog.Completed += delegate { window.Close(); if (string.IsNullOrEmpty(dialog.Text) || string.IsNullOrEmpty(dialog.Url)) { return; } Uri uri = null; try { uri = new Uri(dialog.Url, UriKind.Absolute); } catch (UriFormatException) { try { uri = new Uri("http://" + dialog.Url, UriKind.Absolute); } catch (UriFormatException) { return; } } using (new DocumentHistoryGroup(rtb.DocumentHistory)) { if (rtb.Selection.Text != dialog.Text) { rtb.Selection.Delete(); var run = new C1Run { Text = dialog.Text }; rtb.Selection.Start.InsertInline(run); run.ContentRange.MakeHyperlink(uri, dialog.TargetName); rtb.Selection = run.ContentRange; } else { rtb.Selection.MakeHyperlink(uri, dialog.TargetName); } } rtb.Focus(); }; window.ShowDialog(); }