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

override theme resource 'DataGridColumnHeaderBackgroundBrush' for DataGridColumnHeader in UWP doesn't work in 5.1.0 version #2955

Closed
xiedongweo opened this issue Jun 26, 2019 · 1 comment
Labels
DataGrid 🔠 Issues on DataGrid control needs triage 🔍

Comments

@xiedongweo
Copy link

I'm submitting a...

Bug report (I searched for similar issues and did not find one)

Current behavior

I want to change the default DataGridColumnHeader's background color. I use the following code on XAML page:

<Page.Resources> <SolidColorBrush x:Key="DataGridColumnHeaderBackgroundBrush" Color="Blue"/> </Page.Resources>

I'm using the nuget package 5.1.0(https://www.nuget.org/packages/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/5.1.0)

With this package, the DataGridColumnHeader's background color did get changed.

But I found that if I back to use Package 5.0.0 (https://www.nuget.org/packages/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/5.0.0)

It will work.

Expected behavior

The DataGridColumnHeader's background color should change to blue.

Minimal reproduction of the problem with instructions

`<Page.Resources>
    <SolidColorBrush x:Key="DataGridColumnHeaderBackgroundBrush" Color="Blue"/>
</Page.Resources>
<Grid>
    <controls:DataGrid x:Name="EmployeeGrid"
              ItemsSource="{x:Bind Persons}"
              AutoGenerateColumns="False">
        <controls:DataGrid.Columns>
            <controls:DataGridTextColumn Header="First Name"
                                         Binding="{Binding FirstName}"/>
            <controls:DataGridTextColumn Header="Last Name"
                                         Binding="{Binding LastName}"/>
            <controls:DataGridTextColumn Header="Position"
                                         Binding="{Binding Position}"/>
            <controls:DataGridComboBoxColumn Header="Department"
                                             Binding="{Binding DepartmentId}"                                                  
                                             ItemsSource="{x:Bind Departments, Mode=OneWay}"
                                             DisplayMemberPath="DepartmentName"/>
        </controls:DataGrid.Columns>
    </controls:DataGrid>
</Grid>`

`public sealed partial class MainPage : Page
{
    public List<Department> Departments { get; set; }
    public List<Person> Persons { get; set; }
    public MainPage()
    {
        this.InitializeComponent();
        Departments = new List<Department>
    {
        new Department {DepartmentId = 1, DepartmentName = "R&D"},
        new Department {DepartmentId = 2, DepartmentName = "Finance"},
        new Department {DepartmentId = 3, DepartmentName = "IT"}
    };

        Persons = new List<Person>
    {
        new Person
        {
            PersonId = 1, DepartmentId = 3, FirstName = "Ronald", LastName = "Rumple",
            Position = "Network Administrator"
        },
        new Person
        {
            PersonId = 2, DepartmentId = 1, FirstName = "Brett", LastName = "Banner",
            Position = "Software Developer"
        },
        new Person
        {
            PersonId = 3, DepartmentId = 2, FirstName = "Alice", LastName = "Anderson",
            Position = "Accountant"
        }
    };
    }

    
}

public class Department
{
    public int DepartmentId { get; set; }
    public string DepartmentName { get; set; }
}

public class Person
{
    public int PersonId { get; set; }
    public int DepartmentId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Position { get; set; }
}`

Environment

Nuget Package(s): https://www.nuget.org/packages/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/5.1.0

Package Version(s): 5.1.0

Windows 10 Build Number: 
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] Insider Build (build number: )
- [x] May 2019 Update 18362

App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [x ] October 2018 Update (17763)
- [ ] Insider Build (xxxxx)

Device form factor:
- [x] Desktop
- [ ] Mobile
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT

Visual Studio 
- [ ] 2017 (version: )
- [ ] 2017 Preview (version: )
- [x] 2019 (16.1.0)
@ghost ghost added the needs triage 🔍 label Jun 26, 2019
@michael-hawker michael-hawker added the DataGrid 🔠 Issues on DataGrid control label Jul 30, 2019
@RBrid
Copy link
Contributor

RBrid commented Oct 11, 2019

This must be because of some of Daniel's four changes in DataGrid.xaml:
f22ce48 Daniel Martín González 1/9/2019 7:49:31 AM +00:00 Change DataGridColumnHeaderBackgroundBrush to SystemAltHighColor
3ad0e2e Daniel Martin Gonzalez 1/3/2019 3:50:44 PM +00:00 Merge branch 'master' into datagrid#2373
ca87b5f Daniel Martín González 10/4/2018 8:46:01 PM +00:00 Fix SolidColorBrush to Color
54079a6 Daniel Martín González 10/3/2018 6:36:25 PM +00:00 Fix DataGrid colours not adapting to Dark Theme

I was able to get it working by using:

  <Page.Resources>
    <Color x:Key="MyColumnHeaderBackgroundColor">#C4AF8D</Color>
    <StaticResource x:Key="DataGridColumnHeaderBackgroundColor" ResourceKey="MyColumnHeaderBackgroundColor"/>
  </Page.Resources>

Hope that works for you. Thanks.

@ghost ghost locked as resolved and limited conversation to collaborators Nov 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
DataGrid 🔠 Issues on DataGrid control needs triage 🔍
Projects
None yet
Development

No branches or pull requests

4 participants