views:

33

answers:

3

Hello,

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 Name="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

+1  A: 

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.

Ragoczy
That is not true. The Name is of type String. If I write this in code-behind and can do it and all is fine. Only XAML fails.
Rossen Hristov
I can write this in C#:itemPropertyDefinition.Name = "Player.Count";Why not in XAML????
Rossen Hristov
What does DisplayName have to do with Name??? Just ignore the other two properties. Think only about the the NAme property. It is of type STRING and I want to assign a STRING that contains the dot character. You do not care what i will do with it after that -- I just want to assign it. Do you know why I can or not?
Rossen Hristov
I forgot to mention. The Name property is my property -- ItemPropertyDefinition is just my custom class.
Rossen Hristov
I don't think the XAML parser cares that the property's on your class, I think it just cares that there's a property "Name" and it has rules for it. I can't, for instance, change the Name property of a textbox to include a ".", either in XAML or in code. My guess is if you change the name of the property, it will allow you to include the ".".
Ragoczy
You are right. The parse does not care. I will change it to PropertyName and everything will be fine. Thanks for your help.
Rossen Hristov
A: 

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.

Rossen Hristov
A: 

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.

Martin Liversage
ItemPropertyDefinition is a DependencyObject. It is not a FrameworkElement.
Rossen Hristov