Case Sensitivity of Xaml
Case sensitive markup code = pure evil
To tell you the truth, nobody has asked that question of "Why is Xaml case-sensitive" before, and we made the decision so long ago, I had to go talk to Mike Hillberg to get/recreate the reason why Xaml is case sensitive.
First, what is our behavior:
- Xaml element names and attribute names map directly to Type, Property and Event names in a case-sensitive manner.
- .Net Framework Design Guidelines (MSDN or book@Amazon) call for Pascal casing of Type, Property and Event names. (initial caps and capitalizing words inside the name as well…for example DrawingImage.)
- Therefore, you’ll find that Xaml generally needs to be Pascal cased for Element and Attribute names.
- Attribute values in Xaml are generally case-insensitive. ("True", "true", or "TrUe" all work for a property of type boolean.) This is an artifact of the fact that we call TypeConverters to convert attribute values into the appropriate type, and most .Net type converters are type insensitive.
A few reasons:
- XML is case sensitive for internationalization reasons.
- XHTML, a XML vocabulary, also needed to make a choice; they chose lower case tag and attribute names:
XHTML is case sensitive, where as HTML is not case sensitive. Furthermore XHTML requires that all enumerated attribute values be lower case.
[Note, Xaml, as noted earlier, is a bit looser with attribute values…most attribute values are case-insensitive, but that is up to the TypeConverter which is used for that property value. We recommend that TypeConverters are case-insensitive unless they must be case-sensitive. Path.Data is one of the few case-sensitive attribute values that WPF has.]
- The XHTML spec says why they made that choice:
XHTML documents must use lower case for all HTML element and attribute names. This difference is necessary because XML is case-sensitive e.g. <li> and <LI> are different tags.
Given that we needed to make a choice, we felt that consistency of casing between the type definition and the use in Xaml was the most natural choice.
So that is where we are and why. Thanks to Marius for asking the question and giving the feedback. So far, Marius’ is the first mention I remember seeing of this since we’ve been published "Avalon" externally in October of 2003. I agree that hand editing of Xaml is harder due to this behavior.