DCSIMG
XAML special characters and white spaces - Guy

Guy

Blog about .Net, architechture and Oracle

XAML special characters and white spaces

XAML special characters and white spaces

Some beginner stuff i found a lot of people do not know about.

XAML is based upon the rules of XML. What this means is that characters such as ‘&’, ‘<’, ‘>’ and ‘”’ have their own meaning in XML and the XAML parser will understand them differently then what you intended them for.
If you wish your button’s content to look like this <I am a Button> then you must change your XAML text to  <Button Content="&lt;I am a Button&gt;"></Button>  which creates a button like this:

image

Other character replacements are (don't forget the ‘;’) :

  • &amp; that replaces ‘&’.
  • &quot; that replaces ‘”’.

You also need to pay attention to white spaces. XML, by default, collapses all white spaces, carriage returns and tabs into a single space character if they appear between text and will eliminate the spaces completely before or after the text.

For example, the following XAML:
<TextBox>
carriage return    space         and some more "      ".
   
</TextBox>

will be shown as:

image

To fix this, we need to use the xml:space="preserve" which is set in the element level of the control like this:
<TextBox xml:space="preserve">
carriage return    space         and some more "      ".
   
</TextBox>

Now our text box looks like this:

image

פורסם: Jun 24 2009, 09:13 AM by Guy Shvoron | with 1 comment(s)
תגים:, ,

תוכן התגובה

cvz\xfas כתב/ה:

gsadgasdgs

# December 5, 2011 4:07 PM
שלח תגובה

(שדה חובה)  

(שדה חובה)  

(אופציונלי)

(שדה חובה) 

Please add 3 and 6 and type the answer here:


Enter the numbers above: