private void InsertLink(TextSelection selectedText, Point popupPlacement) { var insertLinkPopup = new InsertLinkPopup(); var existingLinks = selectedText.GetHyperlinksFromSelection(); if (existingLinks == null || existingLinks.Count > 1) { return; } if (existingLinks.Count == 1) { insertLinkPopup.Link = existingLinks[0]?.NavigateUri?.ToString(); } insertLinkPopup.TextToDisplay = selectedText.Text; var popup = new OffsetPopupFactory().CreatePopupOnPoint(popupPlacement); insertLinkPopup.AcceptCommand = new RelayCommand(() => { if (string.IsNullOrEmpty(insertLinkPopup.Link) || string.IsNullOrEmpty(insertLinkPopup.TextToDisplay)) { return; } selectedText.Text = insertLinkPopup.TextToDisplay.RemoveWhitespace(); new BasicHyperLinkFactory().CreateHyperLinkOnTopOfSelectedText(selectedText, insertLinkPopup.Link); popup.IsOpen = false; }); popup.Child = insertLinkPopup; popup.IsOpen = true; }