I have several attached properties in several classes throughout my framework. All of these are mapped into a single xml Namespace using the XmlnsDefinitionAttribute. I have noticed that if I declare some of these attached properties without referring to the class name (the class that actually contains the property, I get the compile-time error:
The property 'XXX' does not exist in XML namespace 'YYY'
To explain better, this happens when I have let’s say a FocusHelper class that has an IsFocused attached property, but try to use it in XAML like this:
<CheckBox my:IsFocused="true"/>.
Notice I specified the xml namespace (which I have correctly declared), but not the class name.
My question is:
Is there a way to achieve this? the error hints me that there is a way to define properties inside namespaces directly. Is this even possible?
This isn’t a XAML issue, this is a C# “issue”. Meaning, you can’t have a “global” property in C#. It must be inside a class.
There is no “global” concept in C#.
In order to get the syntax you want you would have to be able to declare a property globally (i.e. outside the context of a class) and that isn’t possible in C#
This is why framework attached properties also have the class name preceding them (Grid.Column, Canvas.Top)
In the case of the Framework Attached properties (Grid.Column, Canvas.Top etc…) you don’t have to specify the namespace because they are in the “default” namespace
as opposed to your namespace