Search code examples
c#xcodexamarin.mac

Display list of objects in Xamarin.Mac


I have a PCL project. Inside I have 2 classes. One is "Task" and the other one is "Project" that contains a list of tasks. Now I have to make a Cocoa app that uses the project mentioned before. I succeded in installing xcode, visual studio and added a reference to the PCL project. I want to display the list of tasks from a "Project" object in viewcontroller. I searched a lot on google and found out the best way is with a Table View and Array Controller. I can't bind my object to the Array Controller.

First I tried this: this. When I run the code, I get this error. I then found out I need to Expose my objects from C# to Objective-C using expose or register. I tried using expose on the project and I get this error. And here is where I got stuck.

I am new to Xamarin.Mac and this is my first time asking a question. If I did something wrong I am sorry, I will corect myself as soo as possible


Solution

  • AppKit databinding to c# objects have some requirements. The objects must all descend from NSObject. There may be more requirements. Its a pain. I would advise against using AppKit databinding with Xamarin.Mac. A much better approach is to use a NSTableViewDataSource. There is a full example on the MS site: https://learn.microsoft.com/en-us/xamarin/mac/user-interface/table-view