a.lashkevich
Topic Author
Posts: 11
Joined: 23 Sep 2024, 08:50

c++ vector binding

14 Jan 2025, 14:58

hi noesis team, please help

how to bind vector of strings? I tried several ways and got errors in each of them
 
User avatar
jsantos
Site Admin
Posts: 4215
Joined: 20 Jan 2012, 17:18
Contact:

Re: c++ vector binding

15 Jan 2025, 00:21

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.
 
a.lashkevich
Topic Author
Posts: 11
Joined: 23 Sep 2024, 08:50

Re: c++ vector binding

15 Jan 2025, 12:15

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
 
User avatar
jsantos
Site Admin
Posts: 4215
Joined: 20 Jan 2012, 17:18
Contact:

Re: c++ vector binding

16 Jan 2025, 12:00

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.

Who is online

Users browsing this forum: No registered users and 3 guests