I have text box with text wrapping enabled in my Windows Phone 7 app, how do I get the line count at the character selected by the user? For example, if a text box it looked like this:
test
text
bo|x
is
here
, with "|" representing the selected character, the line count would be 3. I need to do this at any point in time, most specifically when the text is changed. I could count the number of newlines in a text box without text wrapping, but this is clearly a different scenario.
Click the Display tab. To enable multiple lines of text to be typed in the text box, select the Multi-line check box, and then optionally do one of the following: To prevent users from being able to insert paragraph breaks in the text box by pressing ENTER, clear the Paragraph breaks check box.
To select the text box, you need to click the border of the text box, and the insertion point disappears. If you press Tab or Ctrl+Tab while the insertion point is visible in the text box, then you only modify the text in the text box; you don't select the next object.
I figured this out myself:
Rect rec = textbox.GetRectFromCharacterIndex(textbox.SelectionStart);
double rectop = rec.Top;
double lineheight = text.LineHeight;
int result = (int)(rectop / lineheight + 1);
result = the selected line.
only a stupid way:
you can handle these event:ManipulationStarted ManipulationCompleted
From the callback args you can find the point(x,y) user point, maybe it is the coordinate of selected place.
and you know the height of everyline from the prop —— lineHeight
and do a division
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With