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

Glitchy ListBox when adding items & setting SelectedIndex #16014

Closed
metal450 opened this issue Jun 13, 2024 · 6 comments
Closed

Glitchy ListBox when adding items & setting SelectedIndex #16014

metal450 opened this issue Jun 13, 2024 · 6 comments
Labels

Comments

@metal450
Copy link

Describe the bug

In my app, I've got a page where I show Log messages in a ListBox:

<ListBox ItemsSource="{Binding LogItems}" SelectedIndex="{Binding SelectedIndex}">
  <ListBox.ItemTemplate>
      <DataTemplate>
         <Border BorderThickness="0,0,0,1" Padding="5 0" >
             <TextBlock Text="{Binding}" Margin="0" Padding="0" TextWrapping="Wrap"/>
         </Border>
     </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>

And:

    public ObservableCollection<string> LogItems
    {
        get => _logItems;
        set => this.RaiseAndSetIfChanged(ref _logItems, value);
    }
    private ObservableCollection<string> _logItems = new ObservableCollection<string>();

    public int SelectedIndex
    {
        get => _selectedIndex;
        set => this.RaiseAndSetIfChanged(ref _selectedIndex, value);
    }
    private int _selectedIndex = -1;

    public void AddLog(string log)
    {
        LogItems.Add(log);
        //SelectedIndex = LogItems.Count - 1;
    }

The above code works fine.

However, if I uncomment the SelectedItem line so that the ListBox will scroll to the bottom each time a new log is added, sometimes it works fine, but randomly it gets all glitched out, with multiple messages overlapping each other. Once that happens, if I scroll up, those overlapping messages will even jump around at random. Here's a video to illustrate:

peek

The behavior is reproducible on Windows, Android, and iOS. It happens on the latest stable version of Avalonia, 11.0.10.

To Reproduce

See description

Expected behavior

No response

Avalonia version

11.0.10

OS

No response

Additional context

No response

@metal450 metal450 added the bug label Jun 13, 2024
@timunie
Copy link
Contributor

timunie commented Jun 13, 2024

please try 11.1 beta as well. Also looks like a custom theme, so best to check with simple sample and vanilla Avalonia

@jp2masa
Copy link
Contributor

jp2masa commented Jun 13, 2024

Duplicate of #14389?

@metal450
Copy link
Author

please try 11.1 beta as well.

Hmm, actually seems to be fixed in the beta. Is the beta safe to use in a production app tho...?

@timunie
Copy link
Contributor

timunie commented Jun 14, 2024

I'd use it as we are close to 11.1 release. But better to test your App carefully before releasing it.

@timunie timunie closed this as completed Jun 14, 2024
@metal450
Copy link
Author

Unfortunately I haven't been able to get 11.1 to work in practice, because it requires .NET 8 (currently I'm on .net 7), and when I upgrade to .net 8, I can no longer initialize Maui.Essentials on iOS.

I'm assuming there's no way to either:

  • Get this fix without upgrading to Avalonia 11.1, or
  • Upgrade to 11.1 without having to upgrade to .NET 8, or
  • I posted the Maui.Essentials issue here; have you seen this occur when upgrading to .Net 8? I know it isn't an Avalonia issue...but I'm kind of stuck if Avalonia is now requiring .Net 8. I included a repro project.

@metal450
Copy link
Author

Just noticed 11.0.11 is out; seems to be fixed there :)

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

3 participants