Virtualization causes ListBoxItems to stretch incorrectly
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
### Description
If UI virtualization is enabled for ListBox/ListView, the width/content layout of items becomes incorrect when the width is reduced.
https://github.com/user-attachments/assets/b143c5a2-5aef-4e37-824f-d4149c6e5585
### Reproduction Steps
https://github.com/CodingOctocat/ListBoxItemWidthIssue
### Expected behavior
At any time, the width of ListBoxItems can be correctly stretched to fit.
### Actual behavior
When the ListBox width is too small, the ListBoxItem width becomes incorrect, requiring manual scrolling of the ListBox to trigger UI redrawing.
### Regression?
_No response_
### Known Workarounds
Data binding is required to bind the width of the ListBoxItem to the width of the virtualization container.
```xaml
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Margin" Value="0,4" />
<!-- Known Workarounds -->
<!--<Setter Property="Width"
Value="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type VirtualizingStackPanel}}}" />-->
```
### Impact
_No response_
### Configuration
- .NET9
- Win11 24h2
- x64
### Other information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.