Skip to content

[API Proposal]: Add GetCharacterIndexFromPoint method to TextBlock #9235

Open

Description

Background and motivation

In my app I need to get the character index from the mouse position. Even though I don't need the capabilities of a TextBox, because TextBlock does not have a method like GetCharacterIndexFromPoint, I need to use the TextBox control instead. The issue is my app creates lots of TextBoxes (which could have been TextBlocks if a TextBlock supported the aforementioned method) and a TextBox is more resource hungry than a TextBlock. So I'd like to avoid paying the price of a TextBox unnecessarily.

API Proposal

public int GetCharacterIndexFromPoint (System.Windows.Point point, bool snapToText);

API Usage

TextBlock textBlock = new();
int characterPosition = textBlock.GetCharacterIndexFromPoint(Mouse.GetPosition(textBlock), false);

Alternative Designs

No response

Risks

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    API suggestionEarly API idea and discussion, it is NOT ready for implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions