UICollection DependenciesProperty
Posted: 27 Mar 2026, 15:00
I have a particular custom Control that defines a Collection DependencyProperty:
This is used to specify some UIElements that get rendered in a Panel in the Control's Template. There is a single instance that is specified in a DataTemplate:
This works as expected as long the Template is not used multiple times, otherwise, unique control instances are created, but they all point to the same collection, and so the items are only rendered by one instance.
I have tried assigning a new empty collection to the Property in the Control's Constructor, which makes the collections unique, but then the items are never added to them.
Is this just an inherent limitation or is there something I am missing?
Code: Select all
pTypeData->RegisterProperty<Noesis::Ptr<Noesis::UICollection<Noesis::BaseComponent>>>(
s_itemsProperty,
"items",
Noesis::FrameworkPropertyMetadata::Create(Noesis::Ptr<Noesis::UICollection<Noesis::BaseComponent>>(),
Noesis::FrameworkPropertyMetadataOptions_None)
);
Code: Select all
<DataTemplate>
...
<CustomControl>
<CustomControl.items>
<Rectangle/>
<Ellipse/>
...
<CustomControl.items>
</CustomControl>
</DataTemplate>
I have tried assigning a new empty collection to the Property in the Control's Constructor, which makes the collections unique, but then the items are never added to them.
Is this just an inherent limitation or is there something I am missing?