Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unimplemented ScrollToHorizontalOffset and ScrollToVerticalOffset #461

Open
stiggronnestad opened this issue Nov 3, 2024 · 0 comments
Open

Comments

@stiggronnestad
Copy link

stiggronnestad commented Nov 3, 2024

Version: 11.1.0

During an attempt to lock 2 AvaloniaEdit vertical/horizontal offsets I encountered some issues. It seems that ScrollToHorizontalOffset and ScrollToVerticalOffset was never implemented (or commented out) at some point. Avalonia 11.2 ScrollViewer does not have this API currently.

The underlying ScrollViewer is internal, so I'm not sure what the best approach is.

        /// <summary>
        /// Scrolls to the specified position in the document.
        /// </summary>
        public void ScrollToHorizontalOffset(double offset)
        {
            ApplyTemplate(); // ensure scrollViewer is created
            //if (scrollViewer != null)
            //    scrollViewer.ScrollToHorizontalOffset(offset);
        }

        /// <summary>
        /// Scrolls to the specified position in the document.
        /// </summary>
        public void ScrollToVerticalOffset(double offset)
        {
            ApplyTemplate(); // ensure scrollViewer is created
            //if (scrollViewer != null)
            //    scrollViewer.ScrollToVerticalOffset(offset);
        }

Edit: I tested a simple solution which works fine.

        /// <summary>
        /// Scrolls to the specified position in the document.
        /// </summary>
        public void ScrollToHorizontalOffset(double offset)
        {
            ApplyTemplate(); // ensure scrollViewer is created
            if (ScrollViewer != null)
                ScrollViewer.SetValue(ScrollViewer.OffsetProperty, new Vector(offset, ScrollViewer.Offset.Y));
        }

        /// <summary>
        /// Scrolls to the specified position in the document.
        /// </summary>
        public void ScrollToVerticalOffset(double offset)
        {
            ApplyTemplate(); // ensure scrollViewer is created
            if (ScrollViewer != null)
                ScrollViewer.SetValue(ScrollViewer.OffsetProperty, new Vector(ScrollViewer.Offset.X, offset));
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant