How to properly bind collections of boxed types without reflection?
Posted: 19 Dec 2025, 00:52
I have seen a few threads here for dynamic type VMs and i am doing the same. I have single variables and commands working and am now working on collection variable. The collection variable does not update the view, i have done much debugging and everything seems in order for me.
here is my dynamic property which works great for single but fails for collection.
i can breakpoint and see that GetComponent() is correctly returning the observable collection but the view does not update. what is GetComponent() expecting me to turn if not an observable list of boxed types?
additionally when i try and set a textblock to collection[0] I get a interesting result after setting my view model in code ( xaml shown in top, works good in app studio )
my type building looks like this
Thank you for reading! ( btw i posted this in the wrong group, apologies! )
Code: Select all
// this works perfectly in app studio and i can see my collections and collections[0]
<Class Name="ViewModel">
<Property Name="favorite_colors" Type="Collection" SubType="String" CollectionMinItemCount="0" CollectionMaxItemCount="10"/>
</Class>
<ItemsControl ItemTemplate="{DynamicResource DataTemplate.001}" ItemsSource="{Binding Path=favorite_colors}"/>
<TextBlock Text="{Binding Path=favorite_colors[0]}" />
Code: Select all
// doing collections does not work for me, this is the problem code
collection = *new Noesis::ObservableCollection<Noesis::BaseComponent>();
collection->Add(Noesis::Boxing::Box<Noesis::String>(value.c_str()));
dynamicObject->values[param_name] = collection; // is a dictionary
OnPropertyChanged(param_name);
Code: Select all
class DynamicTypeProperty : public Noesis::TypeProperty
{
public:
DynamicTypeProperty(Noesis::Symbol name, const Noesis::Type* type)
: Noesis::TypeProperty(name, type) {}
Noesis::Ptr<Noesis::BaseComponent> GetComponent(const void* ptr) const override
{
const DynamicObject* obj = static_cast<const DynamicObject*>(ptr);
return obj->values[GetName().Str()];
}
void SetComponent(void* ptr, Noesis::BaseComponent* value) const override
{
DynamicObject* obj = static_cast<DynamicObject*>(ptr);
obj->values[GetName().str()] = Noesis::Ptr<Noesis::BaseComponent>(value));
}
void* GetContent(const void* ptr) const override
{
return nullptr;
}
};
additionally when i try and set a textblock to collection[0] I get a interesting result after setting my view model in code ( xaml shown in top, works good in app studio )
Pretty curious as I proved to myself that GetComponent() is returning the observable list and not a boxed string. Without source i cannot tell what happens after GetComponent();[NOESIS/W] Can't solve PropertyPath: Can't use index/key '0' with a non list/dictionary object 'Boxed<String>'
[NOESIS/E] Binding failed: Path=favorite_colors[0], Source=PlayerViewModel(''), Target=TextBlock(''), TargetProperty=TextBlock.Text
my type building looks like this
Code: Select all
// have tried both of these
builder->AddProperty(new DynamicTypeProperty(Noesis::Symbol(prop.property_name.c_str()), Noesis::TypeOf<Noesis::BaseObservableCollection>()));
builder->AddProperty(new DynamicTypeProperty(Noesis::Symbol(prop.property_name.c_str()), Noesis::TypeOf<Noesis::ObservableCollection<Noesis::BaseComponent>>()));
Thank you for reading! ( btw i posted this in the wrong group, apologies! )