1

I have a C# Windows Phone 8 app with a ComponentOne RichTextBox contorl. How do I get the selected HTML that corresponds to the current value of a RichTextBox control's SelectedText property? (the current selection)

For example, suppose I have the current HTML in the RichTextbox:

<p>Some text</p><p><i>italicized text</i></p><p>Text not selected</p>

And the user selects "Some text" and "italicized text" by tapping. The SelectedText property will be "some text italicized text" and what I want to back as the selected HTML is:

<p>Some text</p><p><i>italicized text</i></p>

Is there a way to do this without doing some really messy operation walking the HTML while accumulating tags until the accumulated text matches the SelectedText property?

Robert Oschler
  • 14,153
  • 18
  • 94
  • 227
  • have you tried rtb.GetTextRange(rtb.SelectionStart,rtb.SelectionLength).Html – Shawn Kendrot Mar 18 '14 at 18:32
  • @ShawnKendrot I just tried that after highlighting some text and it returned the entire HTML document "...". – Robert Oschler Mar 18 '14 at 18:37
  • or rtb.Selection.Html – Shawn Kendrot Mar 18 '14 at 18:38
  • @ShawnKendrot Same thing. It looks like they didn't enhance the Html property to be constrained by the current selection. – Robert Oschler Mar 18 '14 at 18:46
  • That's what the TextRange is suppose to be, a range of text... I have not worked with the controls, just guessing based on docs. Can you debug and get any info from the TextRange object by opening it up? – Shawn Kendrot Mar 18 '14 at 18:59
  • @ShawnKendrot TextRange itself fine works and does return the selected text, but the attached Html property isn't basing its output off of the current range. – Robert Oschler Mar 18 '14 at 19:20
  • Sounds like a bug based on [the docs](http://helpcentral.componentone.com/nethelp/C1PhoneRichTextBox/#!XMLDocuments/RichTextBox/html/AllMembers_T_C1_Phone_RichTextBox_Documents_C1TextRange.htm) "When getting the Html, the result is the same as deleting the rest of the document except the range" – Shawn Kendrot Mar 18 '14 at 19:25
  • @ShawnKendrot Could be, all I know is what I see. Thanks for working with me on it in any case. – Robert Oschler Mar 18 '14 at 19:28

0 Answers0