How can I enter a string literal containing the dot character in XAML (Silverlight 4)?
Maybe this is something obvious, but here is what I have. I need to write a string in XAML. That is ok, but if the string has the dot character inside it, the XAML parser fails. I tried all kinds of escaping, but nothing helps.
<datafilter:ItemPropertyDefinition N开发者_运维百科ame="Players.Count"
PropertyType="{Binding Int32, ElementName=Types}"
DisplayName="Squad Size">
</datafilter:ItemPropertyDefinition>
No matter what I do, I cannot have a string literal that contains a dot. The XAML parser always tells:
"Players.Count' is not a valid value for Name".
Any ideas? Thanks in advance.
Rossen
It's not the literal, it's the Name property. You can't have a "." in Name, just as you can't name a variable with a "." in code.
In your example, accessing the DisplayName property would be written as: Players.Count.DisplayName, which wouldn't make sense.
The appropriate naming convention in your case would be, I think, PlayerCount.
I found out what is going on. It is amazing. Just a bad coincidence of naming.
ItemPropertyDefinition is my OWN class. It is a DependencyObject. It has a string DependencyProperty called Name. It is called Name because, well, it holds the Name of the thing.
Maybe the "clever" XAML parser does not allow dots in a Name property completely ignoring that fact that this is MY class and this is MY property.
I have to change this to be called PropertyName otherwise I am messing up DependencyObject.Name property.
XAML gives special treatment to the names of elements using the Name
and x:Name
attribute. From FrameworkElement.Name Property:
The string values used for Name have some restrictions, as imposed by the underlying x:Name Directive defined by the XAML specification. Most notably, a Name must start with a letter or the underscore character (_), and must contain only letters, digits, or underscores. For more information, see WPF XAML Namescopes.
In general you should avoid to define a Name
property when defining a FrameworkElement
.
精彩评论