krishnaa
krishnaa

Reputation: 11

Get the position (x,y) of the first character of the text within a text box in WPF

How to convert the first character index within the textbox to the x,y coordinates in WPF ie basically I need the point loaction of the first character of the text within a textbox in WPF.I am capturing the x,y coordinates of the textbox wrt image displayed on the window screen in wpf
UIElement container = (MainImage) as UIElement; System.Windows.Point relativeLocation = textboxinsert.TranslatePoint(new System.Windows.Point(0, 0), container);
But unaware to do it for text within a textbox in wpf.Any pointers would be really helpful?

Upvotes: 1

Views: 1439

Answers (1)

Marius Steinbach
Marius Steinbach

Reputation: 626

If you only need to find the position of the first appearance, you will be fine with TextBox.Text.IndexOf('x');.

If you need to row too, you will need to make a difference between the lines that are broken because of the size of the textbox and the ones that are there because the user has pressed Enter.

You can do it by using a MemoryStream and a StreamReader.

Upvotes: 1

Related Questions