locked
Preserving whitespace in Run element

    Question

  • When formatting a paragraph as so -

    <RichTextBlock>

    <Paragraph xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <Run></Run> <InlineUIContainer><TextBlock >Words here</TextBlock></InlineUIContainer> <Run xml:space="preserve"> </Run> <InlineUIContainer><TextBlock>More words here</TextBlock></InlineUIContainer> <Run xml:space="preserve"> Lastly some words here</Run> </Paragraph> </RichTextBlock>

    The <Run> element containing a single space is never displayed and ignore the space=preserve property. However the last run with a leading space is displayed correctly.

    How can I get a run containing a single space to display ?

    Tuesday, December 30, 2014 2:07 PM

Answers

  • Thanks for the insights into this issue!

    I found a workaround by replacing the white space in a run element with the XAML encoded version &#160;

    Thanks!

    • Marked as answer by BradStevenson Sunday, January 04, 2015 5:13 PM
    Sunday, January 04, 2015 5:13 PM

All replies

  • Hi BradStevenson,

    You can see the whitespace working principle in XAML from http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh758290.aspx.

    As we can see, “A space immediately following the start tag is deleted.it should be removed by the system. But when we add whitespace before other characters, I think it is used as a string, because “If the type of the property is Object, then the inner text is parsed as a single String. If there are intervening element tags, this results in a XAML parser error, because the Object type implies a single object (String or otherwise).” When whitespace in inner text. You can find these explanation from the above link.

    So if you want to preserve the whitespace, use whitespace in string and make the system considering it as inner text.

    Feel free to let me know if you have any concerns.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Wednesday, December 31, 2014 5:30 AM
    Moderator
  • Thanks for the insights into this issue!

    I found a workaround by replacing the white space in a run element with the XAML encoded version &#160;

    Thanks!

    • Marked as answer by BradStevenson Sunday, January 04, 2015 5:13 PM
    Sunday, January 04, 2015 5:13 PM