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 flicker when we data-bind the visibility of the items #16771

Open
dr1rrb opened this issue May 17, 2024 · 5 comments
Open

ItemsRepeater flicker when we data-bind the visibility of the items #16771

dr1rrb opened this issue May 17, 2024 · 5 comments
Labels
area/items-repeater Categorizes an issue or PR as relevant the ItemsRepeater control difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working project/items 🧾 Categorizes an issue or PR as relevant to items (ItemsControl, ItemsRepeater, ...)

Comments

@dr1rrb
Copy link
Member

dr1rrb commented May 17, 2024

Current behavior

When we have a view like this:

<ItemsRepeater ItemsSource="{Binding MySource}">
    <ItemsRepeater.ItemTemplate>
        <DataTemplate>
            <Border>
                <TextBlock Text="{Binding Value}" Visiblity="{Binding IsVisible}" />
            </Border>
        </DataTemplate>
    </ItemsRepeater.ItemTemplate>
</ItemsRepeater>

Note the binding on Visiblity="{Binding IsVisible}" on the TextBlock.

This cause some flicker when scrolling, especially if there are nested ItemsRepeater doing the same!

Expected behavior

No flicker and proper alignment of items!

How to reproduce it (as minimally and precisely as possible)

Workaround

DO NOT Data-bind the visibility of items, instead remove and add them back to the MySource collection.


*************************** IMPORTANT ***************************

The "workaround" is actually the recommended way to do as it is (significantly) more performant as:

  1. It avoids materialization of items that are finally hidden
  2. Data-binding the visibility might (always?) cause an additional layouting pass!

Works on UWP/WinUI

None

NuGet package version(s)

5.2

Affected platforms

Uno ... but the issue might be the same on windows and should be tested first!

@dr1rrb dr1rrb added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. labels May 17, 2024
@Youssef1313
Copy link
Member

@dr1rrb Is this about ItemsRepeaterManyItems sample? Are you testing Gtk or WPF?

For Gtk, it's a known problem which I tried to fix, but the fix broke Gallery canary so it was reverted. See #15811

@Youssef1313
Copy link
Member

I can try another fix though

@jeromelaban jeromelaban added project/items 🧾 Categorizes an issue or PR as relevant to items (ItemsControl, ItemsRepeater, ...) area/items-repeater Categorizes an issue or PR as relevant the ItemsRepeater control and removed triage/untriaged Indicates an issue requires triaging or verification labels May 22, 2024
@dr1rrb
Copy link
Member Author

dr1rrb commented May 23, 2024

@dr1rrb Is this about ItemsRepeaterManyItems sample? Are you testing Gtk or WPF?

For Gtk, it's a known problem which I tried to fix, but the fix broke Gallery canary so it was reverted. See #15811

Eh eh no it was only to have an issue to track my time ... but since I now found the root cause I can rename it and add details :)

@dr1rrb dr1rrb changed the title ItemsRepeater flicker ItemsRepeater flicker when we data-bind the visility of the items May 23, 2024
@dr1rrb dr1rrb changed the title ItemsRepeater flicker when we data-bind the visility of the items ItemsRepeater flicker when we data-bind the visibility of the items May 23, 2024
@ramezgerges
Copy link
Contributor

This needs a more detailed information.
I tried this but no flickering happened:

// in sample constructor:
ir.DataContext = Enumerable.Range(0, 1000).Select(i => new VM(i.ToString(), i % 2 == 0)).ToList();


public class VM
{
    private string value;
    private bool isVisible;

    public VM(string value, bool isVisible)
    {
        this.value = value;
        this.isVisible = isVisible;
    }
    public string Value => value;
    public bool IsVisible => isVisible;
}
<ScrollViewer Height="400">
      <ItemsRepeater x:Name="ir" ItemsSource="{Binding}">
        <ItemsRepeater.ItemTemplate>
          <DataTemplate>
            <Border Visibility="{Binding IsVisible}">
              <TextBlock Text="{Binding Value}" />
            </Border>
          </DataTemplate>
        </ItemsRepeater.ItemTemplate>
      </ItemsRepeater>
    </ScrollViewer>

However, there is some extreme corruption happening. Reported in #16992

@dr1rrb
Copy link
Member Author

dr1rrb commented Jun 6, 2024

However, there is some extreme corruption happening. Reported in #16992

That's what I call "flicker" since it's when you scroll (depending of the scroll direction you will be able to see some items or not). Closing #16992 as duplicate of this.

Edit: Feel free to rename this issue if you find it not descriptive enough ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/items-repeater Categorizes an issue or PR as relevant the ItemsRepeater control difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working project/items 🧾 Categorizes an issue or PR as relevant to items (ItemsControl, ItemsRepeater, ...)
Projects
None yet
Development

No branches or pull requests

4 participants