Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent control styles in GridView rendering after applying windows 11 theme #8753

Open
anjali-wpf opened this issue Jan 30, 2024 · 1 comment

Comments

@anjali-wpf
Copy link
Member

Description

Inconsistent control styles in a GridView after applying the Windows 11 theme. The issue is affecting the rendering of data within the GridView, causing it to display incorrectly.

Reproduction Steps

XAML for GridView -

<ListView Name="lvUsers">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Name" Width="120" DisplayMemberBinding="{Binding Name}" />
            <GridViewColumn Header="Age" Width="50" DisplayMemberBinding="{Binding Age}" />
        </GridView>
    </ListView.View>
</ListView>

Code behind -

List<User> items = new List<User>();
items.Add(new User() { Name = "John Doe", Age = 42 });
items.Add(new User() { Name = "Jane Doe", Age = 39 });
items.Add(new User() { Name = "Sammy Doe", Age = 13 });
items.Add(new User() { Name = "Donna Doe", Age = 13 });

lvUsers.ItemsSource = items;

User class -

public class User
{
    public string Name { get; set; }

    public int Age { get; set; }
}

Expected behavior

The data in the GridView should be rendered correctly, maintaining a consistent appearance and style.

Actual behavior

After applying the Windows 11 theme, the GridView exhibits inconsistent control styles, leading to data rendering issues. This behavior deviates from the expected appearance.

image

Regression?

Same code is working correctly with old theme styles.

image

Known Workarounds

No response

Impact

The inconsistent control styles in the GridView impacts the overall user experience.

Configuration

.NET 9
Windows 11
x64

Other information

No response

@xlsupport
Copy link

Please note that the DataGrid has very similar issues with both Headers and Content.

I also noted that content in the datagrid is aligned to Top/Left by default and requires a lot of work to adjust, which I traced down to two missing TemplateBindings in the style definition for DataGridCell.

I suggest changing the definition of the ContentPresenter in the ControlTemplate defined in Styles\DataGrid.Xaml

<Style x:Key="DefaultDataGridCellStyle" TargetType="{x:Type DataGridCell}">
...
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />

change to:

<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />

HtH, Jurgen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

3 participants