net8floz
Topic Author
Posts: 27
Joined: 16 Dec 2025, 02:34

How to properly bind collections of boxed types without reflection?

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.
// 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]}" />
// 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); 
here is my dynamic property which works great for single but fails for collection.
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;
    }
};
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 )
[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
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();


my type building looks like this
// 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! )
 
net8floz
Topic Author
Posts: 27
Joined: 16 Dec 2025, 02:34

Re: How to properly bind collections of boxed types without reflection?

19 Dec 2025, 03:21

Ended up resolving this was a problem with overwriting the values dictionary of mine that stored the collection with a single part of the collection with some code that was supposed to be in a branch but was not. This cause the collection to get set, leading to correct debug results, and then reset which i was somehow missing in step through.

and the type, for any future readers, the type i claimed in reflection builder was Noesis::TypeOf<Noesis::BaseObservableCollection>()
 
User avatar
sfernandez
Site Admin
Posts: 3364
Joined: 22 Dec 2011, 19:20

Re: How to properly bind collections of boxed types without reflection?

19 Dec 2025, 12:15

For collections to work in bindings the only requirement is that the type implements the IList interface.
So inheriting from BaseObservableCollection, as you mentioned, is just fine.

Who is online

Users browsing this forum: No registered users and 1 guest