c# - How to get the character index in a Silverlight TextBox in a click handler? -


Specifically, what do I want the user to right-click in the text box, locate and index status Save the text where the right click occurs, and later insert some text in that position, when the user once chooses from the context menu that pops due to the right click.

The hard part is getting the index status based on the right-click coordinates.

It's in Silverlight 4.

  Private int _insertPoint; Private Zero User Notification_Myjrayit Button (Object Sender, Mousebutton Avent ARGS E) {// Move the context menu in the context of its container and open it. context menu. Horizontal Offset = E. Gapeption (container). X; ContextMenu.VerticalOffset = e.GetPosition (Container) .Y; ContextMenu.IsOpen = True; // Get the click coordinates relative to the text box int clickX = e.GetPosition (textbox) .X; Int clickY = E. GetPosition (textbox) why; _insertPoint = ?; // Here is the problem} Private Zero SelectFieldToInsert (Object Sender, MouseButtonEventArgs E) {// Close Context Menu ContextMenu.IsOpen = false; Var item = ListBoxItem as the sender; Textbox.Text = textbox.Text.Insert (_insertPoint, "& lt;" + item.Content + "& gt;"); }  

Property on a textbox should help you by link:

< P> If no selection is selected, the StartStart value sets the location of the cursor or sets it.


Comments