How to style the top-left corner of a DataGrid in XAML?

后端 未结 2 621
感动是毒
感动是毒 2020-12-11 09:26

Related to this question: Style datagrid table - Top left corner.

I have a DataGrid (not finished yet, excuse the styles). How can I change the backgrou

相关标签:
2条回答
  • 2020-12-11 09:35

    Right so if we go check out the Default Template and at the very top of the first code example we see;

    <!--Style and template for the button in the upper left corner of the DataGrid.-->
    

    With the declared style template of:

    <Style TargetType="{x:Type Button}"
           x:Key="{ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, 
                   TypeInTargetAssembly={x:Type DataGrid}}">
    

    We now know what/where it is. After that it's just a matter of editing said style part to our hearts content and overriding at the instance level or at the template etc.

    As for your bonus question, if we go check out the same style templates at the <Style TargetType="{x:Type DataGridRowHeader}"> we'll see hard-set BorderThickness on the x:Name="rowHeaderBorder" that we'll just change to whatever. Wherein the same applies to the <Style TargetType="{x:Type DataGridColumnHeader}"> template as there's also another hard-set BorderThickness of "1" on the x:Name="columnHeaderBorder"

    0 讨论(0)
  • 2020-12-11 09:40

    After testing i found only one way to set the color. With the Backcolor from DataGrid and Opacity 0 from Button :-)

    <DataGrid Background="Yellow" RowHeaderWidth="100">
       <DataGrid.Resources>
          <Style TargetType="{x:Type Button}" x:Key="{ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}">
             <Setter Property="Opacity" Value="0" />
          </Style>
       </DataGrid.Resources>
    </DataGrid>
    
    0 讨论(0)
提交回复
热议问题