TextPointer position = richTextBox.CaretPosition; TextPointerContext backwardContext = position.GetPointerContext(LogicalDirection.Backward); TextPointerContext forwardContext = position.GetPointerContext(LogicalDirection.Forward);
TextPointer position = richTextBox.CaretPosition; TextPointerContext backwardContext = position.GetPointerContext(LogicalDirection.Backward); TextPointerContext forwardContext = position.GetPointerContext(LogicalDirection.Forward); if (backwardContext == TextPointerContext.ElementStart && forwardContext == TextPointerContext.ElementEnd) { Inline element = position.Parent as Inline; if (element != null && element is Hyperlink) { // Current position is within a hyperlink } }This code checks whether the current position of the text pointer in a RichTextBox control is within a hyperlink element. It first retrieves the backward and forward context of the text pointer to check if the position is at the start and end of an element, and then checks whether the parent element is a Hyperlink. Package library: System.Windows.Documents.