[Unity] Using a custom type in ItemCollection
I have XAML containing an ItemsControl. I wish to fill the Items property of this ItemsControl with objects of a custom type, like so:
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?
Code: Select all
var itemsControl = FindName<ItemsControl>("MyItemsControl");
var itemCollection = itemsControl.GetItems();
foreach (Foo item in myFooItems)
{
itemCollection.Add(item);
}
-
-
sfernandez
Site Admin
- Posts: 3222
- Joined:
Re: [Unity] Using a custom type in ItemCollection
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:
The following code should work:
Code: Select all
[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