Binding to a Collection in Unity
Hello.
I'd like to bind a listbox to a Collection of data objects so that property values from the data objects can be displayed in the listbox. I saw the Unity sample called Primitives, where the PrimitivesController had a class called UnityObject which was derived from BaseComponent. Do I need to follow that same pattern (e.g. derive from BaseComponent) for all of my data objects? I tried with a POCO object and it didn't work. I think I also saw another example that was using a serializable object. Is that required?
Thanks.
Todd
I'd like to bind a listbox to a Collection of data objects so that property values from the data objects can be displayed in the listbox. I saw the Unity sample called Primitives, where the PrimitivesController had a class called UnityObject which was derived from BaseComponent. Do I need to follow that same pattern (e.g. derive from BaseComponent) for all of my data objects? I tried with a POCO object and it didn't work. I think I also saw another example that was using a serializable object. Is that required?
Thanks.
Todd
-
-
sfernandez
Site Admin
- Posts: 3203
- Joined:
Re: Binding to a Collection in Unity
Our base class for objects used in the GUI is BaseComponent, and should be the base class for any item you add to our Collection.
The SerializableComponent base class is used for objects you want to specify directly in the XAML file (they will be stored inside our own resource and need to be serializable), like the model view in the Commands example.
The SerializableComponent base class is used for objects you want to specify directly in the XAML file (they will be stored inside our own resource and need to be serializable), like the model view in the Commands example.
Re: Binding to a Collection in Unity
Ok, this helps to know for people new to it. I may have missed it but I don't think I saw either of those explicitly stated in the documentation, so if possible it may help others if it can added, just so that it's clear.
Also, would it be possible to have the documentation added as a section on the website that people can browse through prior to downloading the library? I also like to be able to view it from an iPad when I'm not in front of a computer.
Thanks.
Todd
Also, would it be possible to have the documentation added as a section on the website that people can browse through prior to downloading the library? I also like to be able to view it from an iPad when I'm not in front of a computer.
Thanks.
Todd
-
-
sfernandez
Site Admin
- Posts: 3203
- Joined:
Re: Binding to a Collection in Unity
Yes, we are continuously improving our documentation thanks to user feedback. So thanks for your comments.
We decided not to make documentation available from our web to avoid version problems. We thought it was better that each SDK or Unity package had its own documentation updated to the corresponding version. But we take into account your comments, the iPad point worths thinking again
We decided not to make documentation available from our web to avoid version problems. We thought it was better that each SDK or Unity package had its own documentation updated to the corresponding version. But we take into account your comments, the iPad point worths thinking again

Re: Binding to a Collection in Unity
Hi,
Follow up question here: I've bound a Collection to a ListBox ItemsSource, and that seems to work fine, but when I click on one of the items in the list, I get the following error:
Exception: Null item added to collection
Noesis.Error.Check () (at Assets/Plugins/NoesisGUI/Scripts/Core/NoesisError.cs:49)
What does it mean?! Anyone know what I'm doing wrong here?
Thanks!
Follow up question here: I've bound a Collection to a ListBox ItemsSource, and that seems to work fine, but when I click on one of the items in the list, I get the following error:
Exception: Null item added to collection
Noesis.Error.Check () (at Assets/Plugins/NoesisGUI/Scripts/Core/NoesisError.cs:49)
What does it mean?! Anyone know what I'm doing wrong here?
Thanks!
-
-
sfernandez
Site Admin
- Posts: 3203
- Joined:
Re: Binding to a Collection in Unity
Hi,
It is strange that the error shows up when selecting an item of the list, it would have more sense to me if that error occurred when filling the collection with new items
Is it possible to post here a simple xaml+cs that reproduces the error?
Thanks for your collaboration.
It is strange that the error shows up when selecting an item of the list, it would have more sense to me if that error occurred when filling the collection with new items

Is it possible to post here a simple xaml+cs that reproduces the error?
Thanks for your collaboration.
Re: Binding to a Collection in Unity
Hi, thanks for the quick reply! I've attached a simple unity project for you to look at.
Audun
Audun
- Attachments
-
- NoesisTest.rar
- Example listbox collection binding
- (1.9 KiB) Downloaded 370 times
-
-
sfernandez
Site Admin
- Posts: 3203
- Joined:
Re: Binding to a Collection in Unity
Are the attached files the ones producing the "Null item added to collection" error?
Because when I copy these files to my Unity project, error messages are outputed to the console:
Because when I copy these files to my Unity project, error messages are outputed to the console:
[DX9] Assets/NoesisGUI/Samples/_Tests/ItemsSource/Menu.xaml
Ignoring unknown type 'NoesisTest.MenuViewModel' (@9,6)
UnityEngine.Debug:LogWarning(Object)
Noesis.BuildToolKernel:OnLog(Int32, String) (at Assets/Editor/NoesisGUI/NoesisBuildToolKernel.cs:191)
System.Object:wrapper_native_2E81810C()
Noesis.BuildToolKernel:Build() (at Assets/Editor/NoesisGUI/NoesisBuildToolKernel.cs:134)
NoesisPostProcessor:Build(String, Boolean, Boolean) (at Assets/Editor/NoesisGUI/NoesisPostProcessor.cs:252)
NoesisPostProcessor:OnPostprocessAllAssets(String[], String[], String[], String[]) (at Assets/Editor/NoesisGUI/NoesisPostProcessor.cs:215)
UnityEditor.AssetPostprocessingInternal:PostprocessAllAssets(String[], String[], String[], String[], String[])
I can fix all the errors in the scripts and then your sample is working correctly. I can click the items and no exception is thrown.Assets/NoesisGUI/Samples/_Tests/ItemsSource/ItemData.cs(3,29): error CS0246: The type or namespace name `SerializableComponent' could not be found. Are you missing a using directive or an assembly reference?
Re: Binding to a Collection in Unity
Thanks for testing. Yeah, the ItemData.cs needed to be fixed to compile (sorry about that), but this is the example code that fails on my setup.
-
-
sfernandez
Site Admin
- Posts: 3203
- Joined:
Re: Binding to a Collection in Unity
Could you please attach the exact files that produce that error? This way we will be able to fix that bug.
Thanks in advance
Thanks in advance

Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 4 guests