dotnet / dotnet/wpf

Adding the GroupStyle to the ListView control overwrite the ItemsPanel content

Open
#10,920 0 comments 1 reaction 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

I have migrated my _PhotoBook_ from Framework 4.8 to NET 8 and 9 and use the `ListView` control to implement a list of images. The `ItemsPanel` property is using the `WrapPanel` control to get the expected layout. (More details are available [here](https://github.com/DrCQ/ListViewGroupingTest) )
The `ListView` XAML is listed below:
```
<Setter Property="matD:ListViewAssist.ListViewItemPadding" Value="5"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ItemTemplate" Value="{StaticResource ImageItemTemplate}"/>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" IsItemsHost="True"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>

```
Now I wanted to implement the **Grouping** functionality and added just an empty `GroupStyle` to the `ListView`.
```




```
From this point, the `ListView` is ignoring the `ItemsPanelTemplate` content and all items are shown in a vertical stack alignment. I defined own `GroupStyle` templates, but the behavior is still wrong.

The important point is, that this wrong behavior is occurring only one-time, when the `ItemsSource` content is first-time assigned. Switching the **Grouping** functionality on and off again is fixing the alignment problem.

It seems to me, that switching the **Grouping** functionality off is returning to the specified `ItemsPanelTemplate` and the definition of a `GroupStyle` is in some way overwriting this template.

### Reproduction Steps

A Small _PhoneBook_ app showing this wrong behavior is available [here ](https://github.com/DrCQ/ListViewGroupingTest) on Github.

Image

To see the wrong behavior, just use _File→ShowImages_ and select more than 2 JPG images. All images will be displayed in vertical stack alignment.
Then switch the **Grouping** (_Group Content_ Button) on to see the proper grouping alignment based on the _FileCreated_ values. Now switch the **Grouping** off and the expected horizontal warp alignment will be shown.

### Expected behavior

The `ListView` control should use the specified `WrapPanel` to align the items when the `GroupStyle` is specified.

Image

### Actual behavior

The `ListView` control is ignoring the specified `WrapPanel` in the `ItemsPanelTemplate` and is showing the items in a vertical stack.

Image

### Regression?

The XAML and code is working as expected in NET Framework 4.8. The wrong behavior is detected in NET 6, NET 7, NET 8 and NET 9.

Remark: I used for this small app the MaterialDesignFoxXAML library, but this bug is independent of them.

### Known Workarounds

I couldn't find any workarounds in XAML (using `TemplateSelector`) or in code.

### Impact

Just wrong behavior compared to the NET Framework as reference.

### Configuration

This problem is related to the WPF control and probably not dependent on the platform used.

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.