dotnet / dotnet/wpf

The MinWidth defined in the style DataGridRowHeader in APP.xaml results in incorrect rendering and display effects

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

Description

### Description

### Abnormal 1:
```


<Setter Property="MinWidth" Value="40" />

```
The MinWidth defined in the style DataGridRowHeader in **APP.xaml** causes incorrect rendering and display effects.
![image](https://github.com/dotnet/wpf/assets/25739168/46c21b07-6b1d-47e1-8a8e-d6810b741ce9)
(If MinWidth is defined elsewhere for DataGridRowHeader, it is normal.)

### Abnormal 2:
```


<Setter Property="Height" Value="25"/>
<Style.Triggers >
<Trigger Property="IsSelected" Value="True">
<Setter Property="BorderBrush" Value="#a2a2a0"/>
<Setter Property="Background" Value="#FFA500"/>
<Setter Property="BorderThickness" Value="0.5"/>
<Setter Property="FontWeight" Value="UltraBlack"/>
<Setter Property="Foreground" Value="Black"/>
</Trigger>
</Style.Triggers>

```
If this is defined in **MainWindow.xaml**
![image](https://github.com/dotnet/wpf/assets/25739168/9578cbc4-eb5d-431b-afee-d89b99b55354)
If this is defined in **APP.xaml**, only the first of the six cells will present a blue background
![image](https://github.com/dotnet/wpf/assets/25739168/0af13dea-ff36-4db0-8734-4db6680a7763)
### Abnormal 3:
```


<Setter Property="VerticalAlignment"
Value="Center" />
<Setter Property="Background"
Value="#ccc" />
<Style.Triggers>
<Trigger Property="AlternationIndex"
Value="0">
<Setter Property="Background"
Value="#FFFFEF" />
</Trigger>
<Trigger Property="AlternationIndex"
Value="1">
<Setter Property="Background"
Value="#FFFFFF" />
</Trigger>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Background"
Value="#ffcc33" />
<!--<Setter Property="Foreground" Value="White"/>-->
</Trigger>
<Trigger Property="IsSelected"
Value="True">
<Setter Property="Foreground"
Value="Black" />
</Trigger>
</Style.Triggers>

```

Other similar errors include a background exception when defining the Trigger of the AlternationIndex, which is related to the display effect of the first cell in the first row

![image](https://github.com/dotnet/wpf/assets/25739168/0d3e186c-0d5f-403a-aa46-75e2e6a28cdf)

### Code

App.xaml
```







<Setter Property="VerticalAlignment"
Value="Center" />
<Setter Property="Background"
Value="#ccc" />
<Style.Triggers>
<Trigger Property="AlternationIndex"
Value="0">
<Setter Property="Background"
Value="#FFFFEF" />
</Trigger>
<Trigger Property="AlternationIndex"
Value="1">
<Setter Property="Background"
Value="#FFFFFF" />
</Trigger>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Background"
Value="#ffcc33" />
<!--<Setter Property="Foreground" Value="White"/>-->
</Trigger>
<Trigger Property="IsSelected"
Value="True">
<Setter Property="Foreground"
Value="Black" />
</Trigger>
</Style.Triggers>




```

MainWindow.xaml

```










```
MainWindow.xaml.cs

```

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfAppTest
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public List ICDFields { get; set; } = new List { };
public MainWindow()
{
ICDFields.Add(new DataItem("111"));
ICDFields.Add(new DataItem("222"));
ICDFields.Add(new DataItem("333"));
InitializeComponent();
//dgList.ItemsSource = ICDFields;
}
}

public class DataItem
{
[DisplayName("Name")]
[Browsable(true)]
public string Name { get; set; }
[DisplayName("Value")]
[Browsable(true)]
public string Value { get; set; } = "abcd";
public DataItem(string name)
{
Name=name;
}
}
}

```

### Reproduction Steps

1. Create net6.0-windows WpfApp

2. App. xaml defines DataGrid related error styles

3. MainWindow.xaml defines DataGrid

4. MainWindow.xaml.cs binding DataGrid data

5. Run

### Expected behavior

```


<Setter Property="MinWidth" Value="40" />

```
The MinWidth defined in the style DataGridRowHeader in **APP.xaml** causes incorrect rendering and display effects.
![image](https://github.com/dotnet/wpf/assets/25739168/46c21b07-6b1d-47e1-8a8e-d6810b741ce9)

### Actual behavior

No exceptions were thrown, only the interface display was abnormal

### Regression?

unknown

### Known Workarounds

This type of style is not defined in APP.xaml

### Impact

unknown

### Configuration

Windows 11 x64 22H2 22621.2428
VS 2022
net6.0-windows SDK 6.0.318 x64

### 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.