Wednesday, February 22, 2012

Is WPF purely case-sensitive?

What do you think about case sensitivity of WPF?
At first glance, your answer might be YES, it is case-sensitive. But if this has to be true then how come width="auto" & width="Auto" both works fine? On the other hand if is case-insensitive then why do controls don't accept 'width' as its property? You can define the width of a control only using 'Width' (Capital W).

Well the answer is it is partly case-sensitive.

From the MSDN:
XAML is generally speaking case sensitive. For purposes of resolving backing types, WPF XAML is case sensitive by the same rules that the CLR is case sensitive. Object elements, property elements, and attribute names must all be specified by using the sensitive casing when compared by name to the underlying type in the assembly, or to a member of a type. XAML language keywords and primitives are also case sensitive. Values are not always case sensitive. Case sensitivity for values will depend on the type converter behavior associated with the property that takes the value, or the property value type. For example, properties that take the Boolean type can take either true or True as equivalent values, but only because the native WPF XAML parser type conversion for string to Boolean already permits these as equivalents.
Excerpt: Instead of saying WPF is case-sensitive, we can say that XAML IS case-sensitive but the property values are not always case dependent. It depends on property value converter. That's why both 'Auto' and 'auto' works, although in some special cases the property converter might not be able to handle them with case-insensitivity. In other words, you can say that property names are case-sensitive; however, property values might not be case-sensitive.

Sources: MSDN, Stackoverflow.

No comments:

Post a Comment