Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How to detect when NSTextView scrolls vertically

$
0
0

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:

  1. 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.

  1. 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?

Thanks.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>