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

Nested ItemsRepeater causes virtualization bugs #9427

Closed
christosk92 opened this issue Nov 12, 2022 · 12 comments
Closed

Nested ItemsRepeater causes virtualization bugs #9427

christosk92 opened this issue Nov 12, 2022 · 12 comments
Labels

Comments

@christosk92
Copy link

christosk92 commented Nov 12, 2022

Describe the bug

Whenever virtualization is enabled on an ItemsRepeater, it causes unexpected bugs such as out of order data collections.

To Reproduce

  1. Have an items repeater inside another ItemsRepeater representing a grouped structure.
  2. make sure virtualization is enabled for the root ItemsRepeater.
  3. Groups appear out of order, in a random order.

Expected behavior

Items appear in order as they were added.

Screenshots

Screen.Recording.2022-11-12.at.14.06.07.mov

Desktop (please complete the following information):
macOS Monterey 12.6
Avalonia version 0.10.18

  • OS: [e.g. Windows, Mac, Linux (State distribution)]
  • Version [e.g. 0.10.0-rc1 or 0.9.12]

Additional context
Add any other context about the problem here.

XAML code:

     <ScrollViewer>
               <ItemsRepeater   
                   Items="{Binding Items, Mode=OneTime}">
                <ItemsRepeater.Layout>
                    <StackLayout DisableVirtualization="False" Orientation="Vertical"/>
                </ItemsRepeater.Layout>
                <ItemsRepeater.ItemTemplate>
                <DataTemplate x:CompileBindings="True" x:DataType="avaloniaTest2:GroupView">
                    <Grid RowDefinitions="Auto,*">
                        <TextBlock Text="{Binding Title, Mode=OneTime}"/>
                        <ItemsRepeater Grid.Row="1" Items="{Binding Items,
                                 Mode=OneTime}">
                            <ItemsRepeater.Layout>
                              <StackLayout Orientation="Horizontal" DisableVirtualization="True"/>
                            </ItemsRepeater.Layout>
                            <ItemsRepeater.ItemTemplate>
                                <DataTemplate x:DataType="avaloniaTest2:TestItem">
                                    <StackPanel Margin="20" Spacing="8" Width="175" x:Name="PART_Container">
                                        <Image Source="{Binding Cover, Mode=OneWay}"/>
                                        <TextBlock Text="{Binding Title, Mode=OneTime}"
                                                   FontSize="12" Foreground="#6c6e70" 
                                                   ToolTip.Tip="{Binding Title, Mode=OneTime}">
                                            <TextBlock.OpacityMask>
                                                <LinearGradientBrush StartPoint="100%,0%" EndPoint="80%,0%">
                                                    <LinearGradientBrush.GradientStops>
                                                        <GradientStop Color="#00FFFFFF" Offset="0.1" />
                                                        <GradientStop Color="#FFFFFFFF" Offset="1" />
                                                    </LinearGradientBrush.GradientStops>
                                                </LinearGradientBrush>
                                            </TextBlock.OpacityMask>
                                        </TextBlock>

                                        <TextBlock Text="{Binding Description}" 
                                                   FontSize="10" Opacity=".8" ToolTip.Tip="{Binding Description}">
                                            <TextBlock.OpacityMask>
                                                <LinearGradientBrush StartPoint="100%,0%" EndPoint="80%,0%">
                                                    <LinearGradientBrush.GradientStops>
                                                        <GradientStop Color="#00FFFFFF" Offset="0.1" />
                                                        <GradientStop Color="#FFFFFFFF" Offset="1" />
                                                    </LinearGradientBrush.GradientStops>
                                                </LinearGradientBrush>
                                            </TextBlock.OpacityMask>
                                        </TextBlock>
                                    </StackPanel>
                                </DataTemplate>
                            </ItemsRepeater.ItemTemplate>
                        </ItemsRepeater>
                    </Grid>
                </DataTemplate>
            </ItemsRepeater.ItemTemplate>
        </ItemsRepeater>
    </ScrollViewer>
@christosk92
Copy link
Author

Changing the outer ItemsRepeater to ItemsControl does indeed fix this, but of course you miss out on the amazing performance of ItemsRepeater....

@christosk92
Copy link
Author

After closer inspection, it appears that the ItemsRepeater is fetching wrong items?

Note in the screenshot the text of "Title" and "Subtitle"
Screenshot 2022-11-12 at 14 37 20

In the example, Title = Item 6, but Subtitle = Subtitle 1.

If you look at how these groups are generated, there is no way these should be different, as they are generated by the same index
image

@Dolfik1
Copy link

Dolfik1 commented Nov 13, 2022

I also ran into wrong order issues in my project but I did not study the problem in more detail. In addition to wrong order I also observed items duplication.

@thexamlguy
Copy link

We have been seeing the exact same issue on porting one of our WPF app to Avalonia. This has unfortunately put that on hold for now. I understand the issue goes upstream to WinUI so it may be a difficult one to resolve.

@grokys
Copy link
Member

grokys commented Nov 14, 2022

Strange: it would be helpful if someone could try the same repro in WinUI to see if the problem occurs upstream or if it's a problem in the Avalonia implementation, if anyone has time.

@christosk92
Copy link
Author

Issue does not occur in WinUI (tested in Windows app sdk 1.2)

@Dolfik1
Copy link

Dolfik1 commented Nov 15, 2022

Issue does not occur in WinUI (tested in Windows app sdk 1.2)

Could you test AvaloniaUI/Avalonia.Controls.ItemsRepeater#16 in WinUI? I have no Windows-based desktop right now

@thexamlguy
Copy link

Also may be worth looking at ModernWPF's port of ItemsRepeater, which I believe is a direct port of WinUI's, see if they have same issues - https://github.com/Kinnara/ModernWpf

@christosk92
Copy link
Author

Looks like #9677 might be addressing the issue. Excited for the next release!

@christosk92
Copy link
Author

I’ve tested it with the masters RC and I cannot replicate the issue anymore.
I’m assuming it’s been fixed with the new virtualization stuff?

Lmk if anyone else sees the same results

@jmacato
Copy link
Member

jmacato commented Jun 16, 2023

@christosk92 seems like we can close this then :)

@jmacato jmacato closed this as completed Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants