[Mono-osx] Fwd: (Solved) MonoMac bindings trouble

Raymond Reggers raymond at adaptiv.nl
Thu Feb 23 20:25:48 UTC 2012


Solved the problem I was having.

In order to make my bindings work with the XCode xib editor, I extended and exported the bmac bindings from within the MonoMac project.  Vespertilio.Mac is my MonoMac solution, and Vespertilio.Presentation was generated by bmac.

namespace Vespertilio.Mac.Views
{
	[Register ("TextView")]
	partial class TextView : Vespertilio.Presentation.TextView
	{
		public TextView(IntPtr handle) : base(handle)
		{
			
		}
	}
}

Now I can drag a custom view into the xib editor, change the class from NSView to TextView and bind it to my controller. However I'm still wondering why it won't work without this solution. 

Hope this helps anyone having similar problems.

I'm really starting to like MonoMac, a thank you to all the contributors!

Cheers,

Raymond

Begin forwarded message:

> From: Raymond Reggers <raymond at adaptiv.nl>
> Subject: Re: [Mono-osx] MonoMac bindings trouble
> Date: February 14, 2012 11:20:56 PM GMT+01:00
> To: Duane Wandless <duane at wandless.net>
> Cc: mono-osx at lists.ximian.com
> 
> Ok I created the bindings by running this command on the file below:
> 
> mono bmac.exe ${ProjectDir}/Bindings/Vespertilio.Presentation.cs -r System.Drawing
> 
> using MonoMac.Foundation;
> using MonoMac.AppKit;
> 
> namespace Vespertilio.Presentation {
> 	
> 	[BaseType(typeof(NSView))]
> 	interface TextView
> 	{
> 		
> 	}
> }
> 
> And dlopen() is called before anything else, first line in Main(). The library gets loaded because I can see my custom view being displayed.
> 
> For example, I can do this (MainWindowController.cs):
> 
> public override void WindowDidLoad ()
> {
> 	base.WindowDidLoad();
> 	Vespertilio.Presentation.TextView t = new Vespertilio.Presentation.TextView();
> 	this.root.AddSubView(t);
> 	t.setFrame(...
> }
> 
> In this case root is simply a NSView with an outlet to MainWindowController.root.
> 
> BUT if I use interfacebuilder (well XCode now) and replace NSView with TextView and bind an outlet to MainWindowController.root. Then I get an InvalidCastException. If I remove the outlet, everything works and my custom view also shows. 
> 
> Hope this helps.
> 
> Thanks!
> 
> 
> On Feb 14, 2012, at 8:26 PM, Duane Wandless wrote:
> 
>> It might help if you show your bindings... and when did you call dlopen on the framework?
>> 
>> dlopen(...
>> NSApplication.Init()
>> NSApplication.Main()
>> 
>> On Mon, Feb 13, 2012 at 9:14 PM, Raymond Reggers <raymond at adaptiv.nl> wrote:
>> Hi all,
>> 
>> Got another question regarding bindings to my own obj-c classes, my situation and problem is like this:
>> 
>> - I got an obj-c class named TextView which extends NSView, that I compiled into a Cocoa Framework.
>> - Loaded this Framework with Dlcfn.dlopen
>> - Created the bindings using bmac.
>> 
>> Now from c# I can create an instance from my TextView class, add it to an existing view. Works fine.
>> 
>> But it seems my bindings do not work in a reverse manner. For example if I:
>> 
>> - Add my TextView to MainWindow.xib using XCode.
>> - Create an outlet to MainWindowController.
>> 
>> When launching the application, the TextView shows up correctly, but upon resolving the outlet I get a InvalidCastException (stacktrace below). So I tried something else:
>> 
>> - Add my TextView into a NSView
>> - Create an outlet for the NSView (named it root)
>> - Access MainWindowController.root.Subviews[0]
>> 
>> In the debugger this shows up as a NSView. And casting to TextView results in the same InvalidCastException. I must be doing something wrong with my bindings? Hope someone can help.
>> 
>> Kind regards,
>> 
>> Raymond
>> 
>> Stacktrace:
>> 
>> at (wrapper managed-to-native) object.__icall_wrapper_mono_object_castclass (object,intptr) <0x00003>
>> at MonoMac.ObjCRuntime.NSObjectMarshaler`1<Vespertilio.Presentation.TextView>.MarshalNativeToManaged (intptr) <0x0004b>
>> at (wrapper native-to-managed) object.[Vespertilio.Mac.MainWindowController.Void set_root(Vespertilio.Presentation.TextView)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,Vespertilio.Presentation.TextView) <IL 0x0004a, 0x001a0>
>> at (wrapper managed-to-native) MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper (intptr,intptr) <0x00003>
>> at MonoMac.AppKit.NSWindowController.get_Window () [0x0002b] in /Users/raymond/Documents/git/monomac/src/AppKit/NSWindowController.g.cs:371
>> at Vespertilio.Mac.MainWindowController.get_Window () [0x00000] in /Volumes/DATA/vespertilio/Vespertilio/Vespertilio.Mac/MainWindowController.cs:49
>> at Vespertilio.Mac.AppDelegate.FinishedLaunching (MonoMac.Foundation.NSObject) [0x0000b] in /Volumes/DATA/vespertilio/Vespertilio/Vespertilio.Mac/AppDelegate.cs:20
>> at (wrapper dynamic-method) object.[Vespertilio.Mac.AppDelegate.Void FinishedLaunching(MonoMac.Foundation.NSObject)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.Foundation.NSObject) <IL 0x00011, 0x00050>
>> at (wrapper native-to-managed) object.[Vespertilio.Mac.AppDelegate.Void FinishedLaunching(MonoMac.Foundation.NSObject)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.Foundation.NSObject) <IL 0x0006a, 0x001fb>
>> at (wrapper managed-to-native) MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[]) <0x00003>
>> at MonoMac.AppKit.NSApplication.Main (string[]) [0x00000] in /Users/raymond/Documents/git/monomac/src/AppKit/NSApplication.cs:74
>> at Vespertilio.Mac.MainClass.Main (string[]) [0x0000f] in /Volumes/DATA/vespertilio/Vespertilio/Vespertilio.Mac/Main.cs:21
>> _______________________________________________
>> Mono-osx mailing list
>> Mono-osx at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-osx
>> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-osx/attachments/20120223/a3baa106/attachment-0001.html>


More information about the Mono-osx mailing list