Exemplo n.º 1
0
        public void SetSynchronizedScrollView(SessionsScrollView scrollView)
        {
            StopSynchronizing();

            synchronizedScrollView = scrollView;
            NSView synchronizedContentView = synchronizedScrollView.ContentView;

            // Add a notification to know when the scroll view is scrolled
            synchronizedContentView.PostsBoundsChangedNotifications = true;
            NSNotificationCenter.DefaultCenter.AddObserver(NSView.BoundsChangedNotification, (notification) => { 

                // Calculate the difference
                NSClipView changedContentView = (NSClipView)notification.Object;
                RectangleF rect = changedContentView.DocumentVisibleRect();
                PointF curOffset = ContentView.Bounds.Location;
                PointF newOffset = curOffset;
                newOffset.Y = rect.Location.Y;

                // Synchronize position if different
                if (curOffset != newOffset)
                {
                    ContentView.ScrollToPoint(newOffset);
                    ReflectScrolledClipView(ContentView);
                    ContentView.SetNeedsDisplayInRect(ContentView.Frame);
                }
            }, synchronizedContentView);
        }
Exemplo n.º 2
0
        public void StopSynchronizing()
        {
            if (synchronizedScrollView == null)
                return;

            NSView synchronizedContentView = synchronizedScrollView.ContentView;

            // Remove notification
            NSNotificationCenter.DefaultCenter.RemoveObserver(this, "NSViewBoundsDidChangeNotification", synchronizedContentView);
            synchronizedScrollView = null;
        }