Prev | Current Page 135 | Next

Matthew MacDonald

"Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5"

If you try to use these values to set the content of an element,
you??™ll run into trouble because the XAML parser assumes you??™re trying to do something
else??”such as create a nested element.
For example, imagine you want to create a button that contains the text . The
following markup won??™t work:

The problem here is that it looks like you??™re trying to create an element named Click
with an attribute named Me. The solution is to replace the offending characters with entity
references??”specific codes that the XAML parser will interpret correctly. Table 2-1 lists the
character entities you might choose to use. Note that the quotation mark character entity is
only required when setting values using an attribute because the quotation mark indicates the
beginning and ending of an attribute value.
Table 2-1. XML Character Entities
Special Character Character Entity
Less than (<) <
Greater than (>) >
Ampersand (&) &
Quotation mark (") "
Here??™s the corrected markup that uses the appropriate character entities:

CHAPTER 2 n XAML 42
When the XAML parser reads this, it correctly understands that you want to add the text
and it passes a string with this content, complete with angled brackets, to the Button.


Pages:
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147