WPF custom property not recognized by the compiler
I have defined a custom property like below, it's in the namespace
CarApp
. It is supposed to represent the binding source that I would "pass" to a control template, defined as a static resource, by it grabbing it from the parent.
Then, at the top of my xaml component file, I define a local namescope like this
xmlns:local="clr-namespace:CarApp"
. Then, further on, I define my control template, and then my DataGridTemplateColumn
like this:
When I try to compile the app, there's an error:
Which points to the line where I apply the property.
Clearing the temp files (obj) does not help. What's weird tho, is that removing the App.xaml
(the entry point) and then compiling doesn't compain about that, it now says that there's no entry point, and the IDE doesn't show me an error in the xaml
file, so I guess it compiled, but there might be error order at play too.8 Replies
i think you have to name them
GetTemplateBinding
SetTemplateBinding
TemplateBindingProperty
since it probably uses reflection to find and invoke these methods
also nameof(TemplateBinding)
is a const and returns the same thing as typeof(TemplateBinding).Name
ah then
SetProperty
GetProperty
would work tooSet<RegisteredPropertyName>
etc
which in your case is typeof(TemplateBinding).Name
I know, I just used that in a generic base class that got the derived type via a generic parameter, so I couldn't use that
right gotcha
Follow the WPF property naming convention that distinguishes fields from the properties that they represent, by naming the identifier field<property name>Property
. Also, provide staticGet<property name>
andSet<property name>
accessor methods, which lets the property system access your attached property.
Attached properties overview - WPF .NET
Learn about the WPF property system and the capabilities of an attached property, which are global properties settable on any object.
i think visual studio has a code snippet for attached properties
yep
propa