I used this “guide”,
but the difference is that I don’t want to restrict the object Im attaching the property on, to UIElement
I’d like to attach a property to the most generic item : object, so here is my code :
public static readonly DependencyProperty QbNameProperty = DependencyProperty.RegisterAttached(
"QbName",
typeof(string),
typeof(QbName),
new PropertyMetadata("")
);
public static void SetQbName(object obj, string name)
{
obj.SetValue(QbNameProperty, name);
}
public static Boolean GetQbName(object obj)
{
return (Boolean)obj.GetValue(QbNameProperty);
The thing is that SetValue and GetValue do not exist for object… I tried to look everywhere (SO and google) and didnt find any solution but as far as I understood the article I linked, attachedProperties are not restricted to UIElements right ?
So… what should I do ?
ps : to complete my answer I HAVE TO get a Name for some objects Im parsing from a DLL (and display it in a TreeView) so, if I don’t have a Name fields/property, I’ll add the attachment !
You can’t attach properties to Object (or you’ll be able to extend the whole framework..).
Dependency properties can only be used by objects inheriting from DependencyObject.
Then you can use the static methods: