ToddS
Topic Author
Posts: 14
Joined: 24 Jul 2013, 03:49

Binding to a Collection in Unity

30 Jul 2013, 00:14

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

Re: Binding to a Collection in Unity

30 Jul 2013, 14:41

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.
 
ToddS
Topic Author
Posts: 14
Joined: 24 Jul 2013, 03:49

Re: Binding to a Collection in Unity

30 Jul 2013, 15:19

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

Re: Binding to a Collection in Unity

30 Jul 2013, 19:37

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 ;)
 
audun
Posts: 3
Joined: 21 Jan 2014, 12:43

Re: Binding to a Collection in Unity

24 Jan 2014, 11:10

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

Re: Binding to a Collection in Unity

24 Jan 2014, 12:24

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.
 
audun
Posts: 3
Joined: 21 Jan 2014, 12:43

Re: Binding to a Collection in Unity

24 Jan 2014, 15:21

Hi, thanks for the quick reply! I've attached a simple unity project for you to look at.

Audun
Attachments
NoesisTest.rar
Example listbox collection binding
(1.9 KiB) Downloaded 234 times
 
User avatar
sfernandez
Site Admin
Posts: 2997
Joined: 22 Dec 2011, 19:20

Re: Binding to a Collection in Unity

24 Jan 2014, 18:54

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:
[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[])
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?
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.
 
audun
Posts: 3
Joined: 21 Jan 2014, 12:43

Re: Binding to a Collection in Unity

27 Jan 2014, 10:52

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

Re: Binding to a Collection in Unity

27 Jan 2014, 16:30

Could you please attach the exact files that produce that error? This way we will be able to fix that bug.
Thanks in advance ;)

Who is online

Users browsing this forum: Ahrefs [Bot] and 45 guests