英文:
Unable to change background color of DataGridColumnHeader in DataGrid Winui3
问题
I am creating a WinUI3 project and using Datagrid from
CommunityToolkit.WinUI.UI.Controls.DataGrid
I am unable to change DataGridColumnHeader using Setter while Foreground changes perfectly fine. My Code :
<controls:DataGrid.ColumnHeaderStyle>
<Style TargetType="primitives:DataGridColumnHeader">
<Setter Property="FontSize" Value="10"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="Background" Value="Green"/> //This doesnt work
<Setter Property="Foreground" Value="Red"/> //This works
</Style>
</controls:DataGrid.ColumnHeaderStyle>
Output
No matter what I do, the header background remains white. What should I do to change Column Header Background color?
Edit
I saw an issue on Github about it, but didn't make sense to me how to implement it !
https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/3393
英文:
I am creating a WinUI3 project and using Datagrid from
CommunityToolkit.WinUI.UI.Controls.DataGrid
I am unable to change DataGridColumnHeader using Setter while Foreground changes perfectly fine. My Code :
<controls:DataGrid.ColumnHeaderStyle>
<Style TargetType="primitives:DataGridColumnHeader">
<Setter Property="FontSize" Value="10"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="Background" Value="Green"/> //This doesnt work
<Setter Property="Foreground" Value="Red"/> //This works
</Style>
</controls:DataGrid.ColumnHeaderStyle>
Output
No matter what I do, the header background remains white. What should I do to change Column Header Background color?
Edit
I saw an issue on Github about it, but didn't make sense to me how to implement it !
https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/3393
答案1
得分: 1
你需要覆盖这3种颜色:
<Page.Resources>
<Color x:Key="GreenishColor">#FF60B560</Color>
<Color x:Key="YellowishColor">#FFFFF700</Color>
<Color x:Key="BlueishColor">#FF00e5ff</Color>
<StaticResource x:Key="DataGridColumnHeaderBackgroundColor" ResourceKey="GreenishColor"/>
<StaticResource x:Key="DataGridColumnHeaderHoveredBackgroundColor" ResourceKey="YellowishColor"/>
<StaticResource x:Key="DataGridColumnHeaderPressedBackgroundColor" ResourceKey="BlueishColor"/>
</Page.Resources>
你也可以在你的DataGrid
内部这样做:
<controls:DataGrid>
<controls:DataGrid.Resources>
<Color x:Key="GreenishColor">#FF60B560</Color>
<Color x:Key="YellowishColor">#FFFFF700</Color>
<Color x:Key="BlueishColor">#FF00e5ff</Color>
<StaticResource x:Key="DataGridColumnHeaderBackgroundColor" ResourceKey="GreenishColor"/>
<StaticResource x:Key="DataGridColumnHeaderHoveredBackgroundColor" ResourceKey="YellowishColor"/>
<StaticResource x:Key="DataGridColumnHeaderPressedBackgroundColor" ResourceKey="BlueishColor"/>
</controls:DataGrid.Resources>
</controls:DataGrid>
英文:
You need to override these 3 colors:
<Page.Resources>
<Color x:Key="GreenishColor">#FF60B560</Color>
<Color x:Key="YellowishColor">#FFFFF700</Color>
<Color x:Key="BlueishColor">#FF00e5ff</Color>
<StaticResource x:Key="DataGridColumnHeaderBackgroundColor" ResourceKey="GreenishColor"/>
<StaticResource x:Key="DataGridColumnHeaderHoveredBackgroundColor" ResourceKey="YellowishColor"/>
<StaticResource x:Key="DataGridColumnHeaderPressedBackgroundColor" ResourceKey="BlueishColor"/>
</Page.Resources>
you can also do this inside your DataGrid
like this:
<controls:DataGrid>
<controls:DataGrid.Resources>
<Color x:Key="GreenishColor">#FF60B560</Color>
<Color x:Key="YellowishColor">#FFFFF700</Color>
<Color x:Key="BlueishColor">#FF00e5ff</Color>
<StaticResource x:Key="DataGridColumnHeaderBackgroundColor" ResourceKey="GreenishColor"/>
<StaticResource x:Key="DataGridColumnHeaderHoveredBackgroundColor" ResourceKey="YellowishColor"/>
<StaticResource x:Key="DataGridColumnHeaderPressedBackgroundColor" ResourceKey="BlueishColor"/>
</controls:DataGrid.Resources>
</controls:DataGrid>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论