Page 1 of 1

Indexer property for data binding with C++ API

Posted: 11 Jan 2019, 04:29
by nikobarli
Hi,

Just want to make sure. Is the indexer property is supported with C++ API ?

From https://www.noesisengine.com/docs/Gui.C ... orial.html, it seems that it is only supported in C#.

Re: Indexer property for data binding with C++ API

Posted: 11 Jan 2019, 05:47
by nikobarli
Arrggh, I post to a wrong forum !
Sorry, please delete this entry.

Re: Indexer property for data binding with C++ API

Posted: 11 Jan 2019, 13:02
by sfernandez
In C++ your view model hast to implement the IListIndexer or IDictionaryIndexer interface.
class IndexerTest: public BaseComponent, public IListIndexer
{
public:
  int _array[3];

  // IListIndexer
  bool TryGet(uint32_t index, Ptr<BaseComponent>& item) const override
  {
    if (index < 3)
    {
      item = Boxing::Box<int>(_array[index]);
      return true;
    }
    return false;
  }
  virtual bool TrySet(uint32_t index, BaseComponent* item) override
  {
    if (index < 3 && Boxing::CanUnbox<int>(item))
    {
      _array[index] = Boxing::Unbox<int>(item);
      return true;
    }
    return false;
  }
  
  NS_IMPLEMENT_INLINE_REFLECTION(IndexerTest, BaseComponent)
  {
    NsImpl<IListIndexer>();
  }
};
Then you can use the [] in the binding path on your data (in the following sample SomeIndexer property will return an instance of IndexerTest):
<TextBlock Text="{Binding A.B.SomeIndexer[2]}"/>

Re: Indexer property for data binding with C++ API

Posted: 15 Jan 2019, 10:04
by nikobarli
I see.

I have further a question. Is it possible to use enum as an index for binding ?

Something like
<TextBlock Text="{Binding A.B.SomeIndexer[MyEnum.Test]}"/>
Thanks.

Re: Indexer property for data binding with C++ API

Posted: 16 Jan 2019, 17:40
by sfernandez
Unfortunately no, current implementation only expects an integer (IListIndexer) or a string (IDictionaryIndexer). So the 'MyEnum.Test' would be interpreted as a string key into the dictionary indexer.

If you need that feature, could you please report it in our bugtracker?

Re: Indexer property for data binding with C++ API

Posted: 21 Jan 2019, 07:41
by nikobarli
Hi, thanks for the confirmation. I filed the issue here:
https://www.noesisengine.com/bugs/view.php?id=1396

Re: Indexer property for data binding with C++ API

Posted: 21 Jan 2019, 15:08
by jsantos
Thanks Niko!