Susanna.Rowland
Topic Author
Posts: 5
Joined: 07 Apr 2021, 15:20

Attached property class with Noesis::Type property

20 Jul 2021, 18:15

Hi,
I am attempting to create an attached property class, with a registered property of type Noesis::Type, the idea being to be able to add the property to any node, and use the Type Extension to pass a type to my property. The property value would then be used to locate the instance of that type. I have implemented this class in C# for blend and it works, but I am having difficulty implementing it in C++.
This is how it is defined in the xaml:
<my_node common:MyProperty.MyType="{x:Type class:MyClass}"/>
And this is where I am registering the property in code:
NS_IMPLEMENT_REFLECTION(MyPropertyClass, "common.MyProperty")
{
	Noesis::DependencyData* data = NsMeta<Noesis::DependencyData>(Noesis::TypeOf<SelfClass>());
	data->RegisterProperty<Noesis::Type>(MyTypeProperty, "MyType", Noesis::PropertyMetadata::Create(Noesis::Type(Noesis::Symbol::Null())));
}
The problem I am having is that I get multiple build errors as Noesis::Type has no default constructor and it is also attempting to use the deleted copy constructor.
PropertyBuildErrors.PNG
I have also tried using the NsProp macro to register the property, as this has worked in a behavior class, but while that builds, I get the following error at runtime
Can't get or set property 'common.MyProperty.MyType' in a 'my_node' instance.
So I am guessing attached properties have to use RegisterProperty.

Is there a way to register my property that will work? Or is there an alternative type I should be using for this?
Thank you

Tags:
 
User avatar
sfernandez
Site Admin
Posts: 2255
Joined: 22 Dec 2011, 19:20

Re: Attached property class with Noesis::Type property

20 Jul 2021, 19:09

Hi, try with a pointer like we did with FrameworkElement.DefaultStyleKey property:
data->RegisterProperty<const Type*>(DefaultStyleKeyProperty, "DefaultStyleKey",
        FrameworkPropertyMetadata::Create<const Type*>(nullptr));
 
Susanna.Rowland
Topic Author
Posts: 5
Joined: 07 Apr 2021, 15:20

Re: Attached property class with Noesis::Type property

21 Jul 2021, 11:04

That is perfect, thank you! Of all the variations I tried I somehow missed that one

Who is online

Users browsing this forum: No registered users and 1 guest