dotnet / dotnet/wpf

ListView column resizing breaks if there is a DataTrigger on the View property

Open
#7,782 2 comments 0 reactions 1 assignee Claimed by @harshit7962 View on GitHub
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

We were able to reproduce an issue in which the column widths are "stuck" even though the width of the column header can still be modified (see screenshot below).

### Reproduction Steps

1. Create a new C# .NET 7 WPF project "Repro" with default settings in Visual Studio 2022.

2. Add the following code to MainWindow.xaml

```












<Setter Property="View" Value="{StaticResource FirstNameFirst}" />
<Style.Triggers>
<DataTrigger Binding="{Binding UseAlternateView}" Value="true">
<Setter Property="View" Value="{StaticResource LastNameFirst}" />
</DataTrigger>
</Style.Triggers>


```

3. Add the following code to MainWindow.xaml.cs

```
using System.Collections.Generic;
using System.Windows;

namespace Repro
{
public partial class MainWindow : Window
{
public bool UseAlternateView { get; set; } = false;

public MainWindow()
{
InitializeComponent();
this.DataContext = this;

var items = new List()
{
new { FirstName = "John", LastName = "Doe" },
new { FirstName = "Jane", LastName = "Doe" }
};
lvw.ItemsSource = items;
}
}
}
```

4. Run the application.

5. Use the mouse to increase the width of the first column.

### Expected behavior

Widening the header should also increase the width of the content.

### Actual behavior

The columns in the ListView header and the ListView content are "out of sync": The content stays at the same position, only the header column gets widened (see screenshot):

![Screenshot 2023-04-28 135205](https://user-images.githubusercontent.com/20061979/235141911-89039806-243b-420f-befd-d75ec75dc7aa.png)

### Regression?

_No response_

### Known Workarounds

_No response_

### Impact

_No response_

### Configuration

This seems to be an old bug: We were able to reproduce it with .NET 7, .NET Core 3.1 and .NET Framework 4.8. Still, to our surprise, we did not find it documented anywhere (or we did not look hard enough).

### Other information

The `DataTrigger` is never actually triggered, but it is required for reproducing the bug. After removing the DataTrigger, the problem can no longer be reproduced.

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.