amwx / FluentAvalonia

Control library focused on fluent design and bringing more WinUI controls into Avalonia
MIT License
1.04k stars 97 forks source link

TabView - Incorrect tab sizes #424

Closed brads55 closed 1 year ago

brads55 commented 1 year ago

Using v2.0.0 of FluentAvalonia, the sizes of Tabs in a TabView are occasionally not correct. This can be seen in the ControlsGallery sample.

In any of the TabView examples that support closing tabs (though the 2nd example seems to work best), close the last tab then add a new tab without moving the cursor after pressing add, the Tab will be too small until the cursor moves out of the tab, at which point it will resize to the correct size. This is likely a race condition as it doesn't always exhibit this behaviour.

A bit of debugging suggests the issue is that the UpdateTabWidths function is being called too soon. It's being called when the TabItems collection changes, however at that point the underlying presenter panel has not been modified, hence ContainerFromIndex for the tab returns null and nothing is resized.

amwx commented 1 year ago

I think we can post UpdateTabWidths to the Dispatcher to ensure it runs after the next layout pass when the items are realized. Just tested that and it does seem to work.