[EMAIL PROTECTED] How to catch window close event ?
Hi, I try to catch a window close event in my controller class, but the eventhandler never gets executed. This is my code : using System; using System.Collections.Generic; using System.Text; using Monobjc; using Monobjc.Cocoa; namespace windows_events { [ObjectiveCClass] public class MyWindow : NSWindow { public MyWindow() : base() { } public MyWindow(IntPtr native_object) : base(native_object) { } [ObjectiveCMessage(awakeFromNib)] public void awakeFromNib() { Console.WriteLine(this.GetType().ToString() + : awakeFromNib); this.WindowWillClose += new WindowWillCloseEventHandler(MyWindow_WindowWillClose); } void MyWindow_WindowWillClose(NSNotification notification) { Console.WriteLine(window closes); } } } The documentation says, just add an event handler. So I subclassed from NSWindow and just added an event handler, but it never gets executed. Why ? Many thanks, Miguel
Re: [EMAIL PROTECTED] How to catch window close event ?
It works if I set the delegate in interface builder for the window to MyWindow, and if I modify my code to : using System; using System.Collections.Generic; using System.Text; using Monobjc; using Monobjc.Cocoa; namespace windows_events { [ObjectiveCClass] public class MyWindow : NSObject { public MyWindow() : base() { } public MyWindow(IntPtr native_object) : base(native_object) { } [ObjectiveCMessage(awakeFromNib)] public void awakeFromNib() { Console.WriteLine(this.GetType().ToString() + : awakeFromNib); } [ObjectiveCMessage(windowWillClose:)] public void windowWillClose(NSNotification notification) { Console.WriteLine(window closes); } } } Cheers, Miguel Miguel De Buf wrote: Hi, I try to catch a window close event in my controller class, but the eventhandler never gets executed. This is my code : using System; using System.Collections.Generic; using System.Text; using Monobjc; using Monobjc.Cocoa; namespace windows_events { [ObjectiveCClass] public class MyWindow : NSWindow { public MyWindow() : base() { } public MyWindow(IntPtr native_object) : base(native_object) { } [ObjectiveCMessage(awakeFromNib)] public void awakeFromNib() { Console.WriteLine(this.GetType().ToString() + : awakeFromNib); this.WindowWillClose += new WindowWillCloseEventHandler(MyWindow_WindowWillClose); } void MyWindow_WindowWillClose(NSNotification notification) { Console.WriteLine(window closes); } } } The documentation says, just add an event handler. So I subclassed from NSWindow and just added an event handler, but it never gets executed. Why ? Many thanks, Miguel
Re: [EMAIL PROTECTED] How to catch window close event ?
Hello, As stated here (http://www.monobjc.net/index.php?page=events-and-delegates), there may be some problems with some classes as the Objective-C runtime may perform aggressive caching on delegate methods. I am still searching a way to accommodate with this caching while preserving the flexibility of the .NET event handlers... Regards, Laurent Etiemble. 2008/10/16 Miguel De Buf [EMAIL PROTECTED]: It works if I set the delegate in interface builder for the window to MyWindow, and if I modify my code to : using System; using System.Collections.Generic; using System.Text; using Monobjc; using Monobjc.Cocoa; namespace windows_events { [ObjectiveCClass] public class MyWindow : NSObject { public MyWindow() : base() { } public MyWindow(IntPtr native_object) : base(native_object) { } [ObjectiveCMessage(awakeFromNib)] public void awakeFromNib() { Console.WriteLine(this.GetType().ToString() + : awakeFromNib); } [ObjectiveCMessage(windowWillClose:)] public void windowWillClose(NSNotification notification) { Console.WriteLine(window closes); } } } Cheers, Miguel Miguel De Buf wrote: Hi, I try to catch a window close event in my controller class, but the eventhandler never gets executed. This is my code : using System; using System.Collections.Generic; using System.Text; using Monobjc; using Monobjc.Cocoa; namespace windows_events { [ObjectiveCClass] public class MyWindow : NSWindow { public MyWindow() : base() { } public MyWindow(IntPtr native_object) : base(native_object) { } [ObjectiveCMessage(awakeFromNib)] public void awakeFromNib() { Console.WriteLine(this.GetType().ToString() + : awakeFromNib); this.WindowWillClose += new WindowWillCloseEventHandler(MyWindow_WindowWillClose); } void MyWindow_WindowWillClose(NSNotification notification) { Console.WriteLine(window closes); } } } The documentation says, just add an event handler. So I subclassed from NSWindow and just added an event handler, but it never gets executed. Why ? Many thanks, Miguel