I need to detect whenever a NSTextView scrolls vertically (either via user action or programmatically from ScrollRangeToVisible). I've unsuccessfully tried Adding an Observer in a couple of ways, but it's not working. Here is my code:
Adding observer to the View:
MainTextView.PostsBoundsChangedNotifications = true;
MainTextView.AddObserver (this, new NSString("NSViewFrameDidChangeNotification"), NSKeyValueObservingOptions.New, IntPtr.Zero);
public override void ObserveValue (NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
base.ObserveValue (keyPath, ofObject, change, context);
But I never receive any notification. I've changed the keyPath parameter to "Bounds" and various other things, to no avail. Also, I've tried this using the associated NSScrollView.
Adding observer to NSNotificationCenter.DefaultCenter.AddObserver:
NSNotificationCenter.DefaultCenter.AddObserver ("NSViewFrameDidChangeNotification", ViewScrolled, MainTextView);
public void ViewScrolled ( NSNotification notification )
//do something here
This actually works for the keyPath "NSViewFrameDidChangeNotification" but not for "NSViewBoundsDidChangeNotification" which is what I think I need.
Is there something obvious that's wrong with the code above? Or is there another way to accomplish what I need to do?