Exemple #1
0
        void OnCursorPositionChanged(object sender, CursorPositionChangedEventArgs args)
        {
            if (contentElement == null)
            {
                contentElement = GetTemplateChild("ContentElement");
            }

            if (contentElement != null && contentElement is ScrollViewer)
            {
                ScrollViewer scrollview = contentElement as ScrollViewer;
                double       offset     = scrollview.HorizontalOffset;

                // Note: for horizontal scrollage, we offset by 1.0 pixel for the width of the cursor ibeam

                if (args.CursorX < offset)
                {
                    // need to scroll to the left a bit
                    scrollview.ScrollToHorizontalOffset(Math.Max(args.CursorX - 1.0, 0.0));
                }
                else if (args.CursorX > offset + scrollview.ViewportWidth)
                {
                    // need to scroll to the right
                    offset = (args.CursorX + 1.0) - scrollview.ViewportWidth;
                    scrollview.ScrollToHorizontalOffset(offset);
                }

                offset = scrollview.VerticalOffset;
                if (args.CursorY < offset)
                {
                    // need to scroll up a bit
                    scrollview.ScrollToVerticalOffset(args.CursorY);
                }
                else if (args.CursorY + args.CursorHeight > offset + scrollview.ViewportHeight)
                {
                    // need to scroll down a bit
                    offset = (args.CursorY + args.CursorHeight) - Math.Max(args.CursorHeight, scrollview.ViewportHeight);
                    scrollview.ScrollToVerticalOffset(offset);
                }
            }
        }
Exemple #2
0
		void OnCursorPositionChanged (object sender, CursorPositionChangedEventArgs args)
		{
			if (contentElement == null)
				contentElement = GetTemplateChild ("ContentElement");
			
			if (contentElement != null && contentElement is ScrollViewer) {
				ScrollViewer scrollview = contentElement as ScrollViewer;
				double offset = scrollview.HorizontalOffset;
				
				// Note: for horizontal scrollage, we offset by 1.0 pixel for the width of the cursor ibeam
				
				if (args.CursorX < offset) {
					// need to scroll to the left a bit
					scrollview.ScrollToHorizontalOffset (Math.Max (args.CursorX - 1.0, 0.0));
				} else if (args.CursorX > offset + scrollview.ViewportWidth) {
					// need to scroll to the right
					offset = (args.CursorX + 1.0) - scrollview.ViewportWidth;
					scrollview.ScrollToHorizontalOffset (offset);
				}
				
				offset = scrollview.VerticalOffset;
				if (args.CursorY < offset) {
					// need to scroll up a bit
					scrollview.ScrollToVerticalOffset (args.CursorY);
				} else if (args.CursorY + args.CursorHeight > offset + scrollview.ViewportHeight) {
					// need to scroll down a bit
					offset = (args.CursorY + args.CursorHeight) - Math.Max (args.CursorHeight, scrollview.ViewportHeight);
					scrollview.ScrollToVerticalOffset (offset);
				}
			}
		}