Basp
Topic Author
Posts: 22
Joined: 08 May 2014, 10:09

[Unity] Using a custom type in ItemCollection

06 Aug 2014, 16:41

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

Re: [Unity] Using a custom type in ItemCollection

07 Aug 2014, 14:39

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);
}

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 3 guests