nikobarli
Topic Author
Posts: 180
Joined: 26 Apr 2017, 06:23

Indexer property for data binding with C++ API

11 Jan 2019, 04:29

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#.
 
nikobarli
Topic Author
Posts: 180
Joined: 26 Apr 2017, 06:23

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

11 Jan 2019, 05:47

Arrggh, I post to a wrong forum !
Sorry, please delete this entry.
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

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

11 Jan 2019, 13:02

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]}"/>
 
nikobarli
Topic Author
Posts: 180
Joined: 26 Apr 2017, 06:23

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

15 Jan 2019, 10:04

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.
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

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

16 Jan 2019, 17:40

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?
 
nikobarli
Topic Author
Posts: 180
Joined: 26 Apr 2017, 06:23

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

21 Jan 2019, 07:41

Hi, thanks for the confirmation. I filed the issue here:
https://www.noesisengine.com/bugs/view.php?id=1396
 
User avatar
jsantos
Site Admin
Posts: 3905
Joined: 20 Jan 2012, 17:18
Contact:

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

21 Jan 2019, 15:08

Thanks Niko!

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 55 guests