GroupStyle cause ListBox to use the wrong ItemPanel
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
### Description
When adding item to a **empty** `ListBox`, if a `GroupStyle` is defined, `ListBox` will use the GroupStyle's `ItemPanelTemplate` instead of its own. It's important to note that no grouping or sorting is applied to the `ListBox`.
### Reproduction Steps
Build and Run the Project
[DBSolution.zip](https://github.com/dotnet/wpf/files/11471012/DBSolution.zip)
Right Click to open the context menu. Choose "Add"
Take a look in the Visual Tree.
### Expected behavior
WrapPanel is used.

### Actual behavior
But StackPanel is used instead

### Regression?
_No response_
### Known Workarounds
- The ListBox is not empty
If the ItemsSource provided to the ListBox already have item inside.
- Reinitalize the ListBox after adding items
In the project provided, add some items to the ListBox then switch to a different tab and switch back.
The ListBox will be reintialize and use the correct PanelTemplate in these cases.
### Impact
_No response_
### Configuration
.NET 7.0 both Debug and Release Build
Windows 10 Home 19045.2965
x64
Do you know whether it is specific to that configuration? **No**
### Other information
Refereshing the Collection via `CollectionViewSource.GetDefaultView()` doesn't seen to affect anthing
My original [reddit post](https://www.reddit.com/r/csharp/comments/13ae6u6/help_listbox_applying_the_wrong_itempaneltemplate) about the issue. Someone suggested making a bug report
Contributor guide
Assessment
This issue has not been assessed yet.