Page 1 of 1

c++ vector binding

Posted: 14 Jan 2025, 14:58
by a.lashkevich
hi noesis team, please help

how to bind vector of strings? I tried several ways and got errors in each of them

Re: c++ vector binding

Posted: 15 Jan 2025, 00:21
by jsantos
There are bits unfinished about this in our type system. For example, we have the TypeArray and TypeCollection classes and a specialization of TypeOf<> for static arrays.
////////////////////////////////////////////////////////////////////////////////////////////////////
/// TypeOfHelper for static arrays
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class T, uint32_t N> struct TypeOfHelper<T[N]>: public TypeOfHelperBase<T[N], TypeArray>
{
    static Symbol GetName()
    {
        char str[256];
        snprintf(str, 256, "%s[%d]", TypeOf<T>()->GetName(), N);
        return Symbol(str);
    }

    static void Fill(Type* type)
    {
        TypeArray* typeArray = (TypeArray*)(type);
        typeArray->SetElemCount(N);
        typeArray->SetElemSize(sizeof(T));
        typeArray->SetElemType(TypeOf<T>());
    }
};
So static arrays of Noesis::String should work. This could be extended also to support Noesis::Vector and std::vector. If this is important to you, please create a ticket for it.

The alternative right now, less efficient, is having an ObservableCollection of Strings.

Re: c++ vector binding

Posted: 15 Jan 2025, 12:15
by a.lashkevich
thanks for answer,
ObservableCollection of Strings is not working because ObservableCollection works only with BaseComponent* and String is not inherited from BaseComponent,
also Noesis::String items[5]; compiles but I get crash when I try to open screen.
I just want to bind collection of string to combobox ( <ComboBox ItemsSource="{Binding Items}"/> ).
How is best way to do that now? Could you please post working code with TypeOfHelper<Vector<T>> ?
I can wrap my string in view model and use ObservableCollection of view models and get string as field, but it looks not good

Re: c++ vector binding

Posted: 16 Jan 2025, 12:00
by jsantos
ObservableCollection of Strings is not working because ObservableCollection works only with BaseComponent* and String is not inherited from BaseComponent,
You can box the strings in the collection. That should work.