Windows Presentation Foundation

WPF: Preserving Whitespace in XAML.

By default an XML parser will eat whitespace, which is very handy when you want to keep a neat indented structure. However there are many instances where whitespace is significant and must be preserved. The xml:space attribute is used to tell the XML parser how to treat white space in an Elements content.

It should be noted that the xml:space attribute will affect not only the element on which it is declared, but also all descendant elements until a new xml:space attribute is encountered. For this reason we try to use this attribute only where it is needed, and as close to the element that requires it.

The XAML parser supports the xml:space attribute and indeed does the right thing in terms of preserving whitespace. However there is a bug in the XAML parser that prevents us from declaring the attribute on the desired XML element in some situations.

This issue was discussed briefly in a thread I started at the MSDN forums and the most elegant solution is discussed here in more detail.


Subscribe to RSS - WPF