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

ScrollIntoView has one row offset, if scroll backwards #58

Open
VisualAlf opened this issue Nov 11, 2024 · 4 comments
Open

ScrollIntoView has one row offset, if scroll backwards #58

VisualAlf opened this issue Nov 11, 2024 · 4 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@VisualAlf
Copy link

Assume we have a collection with 50 items numbered 1..50. The Table can show 10 items at a time.

Now when we table.ScrollIntoView(<item19>), the item19 shows as the last row in the table.
OK.

But when we have the view start with item35 in the first row and then table.ScrollIntoView(<item19>), the first row shows item20, not item19. That is, scrolling backwards is always one row off.

I checked with the plain ListView so to exclude a (flaw) Winui 3 behavior. Works fine.

@VisualAlf VisualAlf added the bug Something isn't working label Nov 11, 2024
@w-ahmad
Copy link
Owner

w-ahmad commented Nov 14, 2024

this is because of the header row, the ScrollIntoView(object item) doesn't take care of this behavior. The method itself is not overridable. I use a ScrollRowIntoView(int index) method to overcome this issue but the method is private. I can make it visible if that works for you!

please let me know if there are any other possibilities to do that.

@VisualAlf
Copy link
Author

Yes, please. I do need that.

How'd you like something like

    public void ShowRowInView(object? item)
    {
        if (item == null || _scrollViewer is null || Items.IndexOf(item) == -1) return;
        int index = Items.IndexOf(item);

        DispatcherQueue.TryEnqueue(async () =>
        {
            var row = await ScrollRowIntoView(index);
            row?.Focus(FocusState.Programmatic);
        });
    }

So the signature would be the same as for the original void ScrollIntoView(object item)

@w-ahmad
Copy link
Owner

w-ahmad commented Nov 17, 2024

If the intention is to align the method signature with the base class, it should be ScrollRowIntoView(object item) rather than ShowRowIntoView(object item). However, using an object to scroll a row into view would have drawbacks when there are duplicate items in ItemsSource. See the enhancement I proposed here microsoft/microsoft-ui-xaml#9890.

@w-ahmad w-ahmad added the enhancement New feature or request label Nov 17, 2024
@VisualAlf
Copy link
Author

OK with me.
I checked my recent projects and I found that I nearly all the times scroll to the SelectedItem.
So using the index instead of the object would require an additional lookup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants