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

ItemsRepeater scrolls back to 0 when setting focus from end #1423

Closed
grokys opened this issue Oct 10, 2019 · 0 comments · Fixed by #3167
Closed

ItemsRepeater scrolls back to 0 when setting focus from end #1423

grokys opened this issue Oct 10, 2019 · 0 comments · Fixed by #3167
Labels
area-ItemsRepeater bug Something isn't working help wanted Issue ideal for external contributors team-Controls Issue for the Controls team

Comments

@grokys
Copy link

grokys commented Oct 10, 2019

Describe the bug

If the last item in an ItemsRepeater is brought into focus, followed by the preceding items at intervals, the ItemsRepeater occasionally scrolls back to item index 0.

Steps to reproduce the bug

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <TextBlock Name="current"/>
        <ScrollViewer HorizontalScrollBarVisibility="Disabled"
                      VerticalScrollBarVisibility="Auto"
                      Grid.Row="1" Width="250" Height="350">
            <Border Background="LightBlue">
                <controls:ItemsRepeater x:Name="repeater">
                    <controls:ItemsRepeater.ItemTemplate>
                        <DataTemplate>
                            <Border BorderBrush="Red" BorderThickness="1">
                                <TextBlock HorizontalAlignment="Stretch" Text="{Binding}"/>
                            </Border>
                        </DataTemplate>
                    </controls:ItemsRepeater.ItemTemplate>
                </controls:ItemsRepeater>
            </Border>
        </ScrollViewer>
    </Grid>
    public sealed partial class BasicDemo : Page
    {
        readonly DispatcherTimer timer = new DispatcherTimer();
        int index;

        public BasicDemo()
        {
            this.InitializeComponent();
            repeater.ItemsSource = Enumerable.Range(0, 10000).Select(x => x.ToString()).ToList();
            timer.Interval = TimeSpan.FromMilliseconds(500);
            timer.Tick += Timer_Tick;
            timer.Start();
        }

        private void Timer_Tick(object sender, object e)
        {
            if (index == 0)
            {
                index = 9999;
            }
            else
            {
                --index;
            }

            current.Text = index.ToString();

            var element = repeater.GetOrCreateElement(index);
            element.UpdateLayout();
            element.StartBringIntoView();
        }
    }

Screenshots

xgK38GxcWl

Version Info

Current master (a53a650)

Windows 10 version Saw the problem?
Insider Build (xxxxx)
May 2019 Update (18362) Yes
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Mobile
Xbox
Surface Hub
IoT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-ItemsRepeater bug Something isn't working help wanted Issue ideal for external contributors team-Controls Issue for the Controls team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants