[Mono-osx] How to export an array

Andrew Ayre andy at britishideas.com
Fri Sep 16 05:29:26 EDT 2011


OK, I have it partially working:

public class Foo : NSObject
{
  int Bar;
  [Export]
  string Name;
  ...
}

[Export]
public Foo[] MyFoos { get; set; }

[Export]
public Foo CurrentFoo { get; set; }

void Initialize()
{
  MyFoos = new Foo[2];
  MyFoos[0] = new Foo();
  MyFoos[1] = new Foo();
}

In Interface Builder I can bind the PopUpButton as follows:

  Content = File's Owner.MyFoos
  Content Values = File's Owner.MyFoos.Name
  Selected Object = File's Owner.CurrentFoo

When I start my application the pop up button shows "No value". In the
form controller's Initialize function I can fix this with:

CurrentFoo = MyFoos[0];

That works fine. The problem is that this line of code doesn't work
anywhere else. If I move it to an action for a button click it does
nothing. Sure, the value of CurrentFoo changes, but the setting shown in
the pop up button does not.

I also tried:

InvokeOnMainThread(delegate { CurrentFoo = MyFoos[0]; });

and:

MyPopUpButton.WillChangeValue("CurrentFoo");
CurrentFoo = MyFoos[0];
MyPopUpButton.DidChangeValue("CurrentFoo");

but none of those helped.

Selecting an item from the pop up button works - it updates the value of
CurrentFoo as expected.

What am I doing wrong?

Many thanks again, Andy

On 9/15/2011 10:32 AM, Andrew Ayre wrote:
> I don't get a crash if I change int to NSNumber in my example code, so
> this makes me think that I can only export NS/Mac types. Is that right?
> 
> Ideally I would like to create an array of my own types and bind them to
> a NSPopupButton with control over the displayed text. This is trivial in
> .NET/WinForms. Is it possible with MonoMac somehow?
> 
> thanks, Andy
> 
> On 9/14/2011 1:47 PM, Andrew Ayre wrote:
>> Hi, Here is my simple test code, which is on MainWindowController.cs:
>>
>> private int[] _MyValues = { 1, 2, 3 };
>>
>> [Export ("myValues")]
>> public int[] MyValues
>> {
>>   get { return _MyValues; }
>>   set { _MyValues = value; }
>> }
>>
>> I haven't tried to bind the array to anything and it's not used anywhere
>> in the code. When I start my application it crashes immediately and
>> every time with SIGABRT in native code:
>>
>> *Assertion: should not be reached at marshal.c:7600
>>
>> object.__icall_wrapper_mono_delegate_to_ftnptr(object) <IL 0x00021,
>> 0xffffffff>
>>
>> I am using the current MonoMac and MonoDevelop on SnowLeopard. I'm sure
>> I am misunderstanding how to use it - can anyone please give me some
>> hints? Thanks.
>>
>> regards, Andy
>>
> 

-- 
Andy
PGP Key ID: 0xDC1B5864


More information about the Mono-osx mailing list