Page 1 of 1

[Unity] Using a custom type in ItemCollection

Posted: 06 Aug 2014, 16:41
by Basp
I have XAML containing an ItemsControl. I wish to fill the Items property of this ItemsControl with objects of a custom type, like so:
var itemsControl = FindName<ItemsControl>("MyItemsControl");
var itemCollection = itemsControl.GetItems();

foreach (Foo item in myFooItems)
{
  itemCollection.Add(item);
}
This fails, because Add() needs a BaseComponent, and Foo is not a basecomponent. Is there any way to deal with this or can I only use built in types in this manner?

Re: [Unity] Using a custom type in ItemCollection

Posted: 07 Aug 2014, 14:39
by sfernandez
Currently our framework only supports adding items to our collections that inherit from Noesis.BaseComponent. We are working to remove that limitation in a future version.

The following code should work:
[Noesis.Extended]
public class Person : Noesis.BaseComponent
{
    public string Name { get; set; }
}

...

Person[] persons = new Person[]
{
    new Person { Name = "Mike" },
    new Person { Name = "John" },
    new Person { Name = "Pete" }
};

var itemsControl = FindName<ItemsControl>("MyItemsControl");
var itemCollection = itemsControl.GetItems();

foreach (Person person in persons)
{
    itemCollection.Add(person);
}