如何在XAML中设置DataGrid的左上角样式?

Dan*_*ett 3 .net c# wpf xaml datagrid

与此问题相关:样式数据网格表 - 左上角.

我有一个DataGrid(尚未完成,借口风格).如何使用XAML更改左上角的背景颜色(与其他问题中的C#相反)?

这是我目前的XAML:

<DataGrid x:Name="DataGrid" HorizontalAlignment="Center" VerticalAlignment="Center"
          ColumnWidth="100" ColumnHeaderHeight="50" RowHeight="50" RowHeaderWidth="115" Padding="5"
          BorderBrush="#FF646464" FontSize="18" FontFamily="Segoe UI"
          CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" CanUserResizeRows="False"
          Focusable="False" IsEnabled="False" IsReadOnly="True">
    <DataGrid.Background>
        <SolidColorBrush Color="#FFFFFFC8"/>
    </DataGrid.Background>
    <DataGrid.Columns>
        <DataGridTextColumn Binding="{Binding In}" Header="In"/>
        <DataGridTextColumn Binding="{Binding Out}" Header="Out"/>
        <DataGridTextColumn Binding="{x:Null}" Header="Hours"/>
    </DataGrid.Columns>
    <DataGrid.ColumnHeaderStyle>
        <Style TargetType="{x:Type DataGridColumnHeader}">
            <Setter Property="Background" Value="#FFFFFFC8"/>
            <Setter Property="BorderBrush" Value="DarkSlateGray"/>
            <Setter Property="BorderThickness" Value="1, 2"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="5"/>
        </Style>
    </DataGrid.ColumnHeaderStyle>
    <DataGrid.RowBackground>
        <SolidColorBrush Color="Transparent"/>
    </DataGrid.RowBackground>
    <DataGrid.RowHeaderStyle>
        <Style TargetType="{x:Type DataGridRowHeader}">
            <Setter Property="Background" Value="#FFFFFFC8"/>
            <Setter Property="BorderBrush" Value="DarkSlateGray"/>
            <Setter Property="BorderThickness" Value="2, 1"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="Padding" Value="5"/>
        </Style>
    </DataGrid.RowHeaderStyle>
    <DataGrid.RowHeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}}, Path=Item.Day}"/>
        </DataTemplate>
    </DataGrid.RowHeaderTemplate>
</DataGrid>
Run Code Online (Sandbox Code Playgroud)

额外奖励:如何在当前只有1px边框的行/列标题上获得2px边框?

Chr*_* W. 7

是的,如果我们去看看默认模板,并在我们看到的第一个代码示例的最顶部;

<!--Style and template for the button in the upper left corner of the DataGrid.-->
Run Code Online (Sandbox Code Playgroud)

使用声明的样式模板:

<Style TargetType="{x:Type Button}"
       x:Key="{ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, 
               TypeInTargetAssembly={x:Type DataGrid}}">
Run Code Online (Sandbox Code Playgroud)

我们现在知道它是什么/在哪里.在那之后,只需要将所述样式部分编辑到我们的心灵内容并覆盖实例级别或模板等.

至于你的奖金问题,如果我们在签出同一样式模板<Style TargetType="{x:Type DataGridRowHeader}">,我们会看到硬盘设置BorderThicknessx:Name="rowHeaderBorder",我们只会改变什么.其中同样适用于<Style TargetType="{x:Type DataGridColumnHeader}">模板,因为还有另一个硬盘BorderThickness"1"x:Name="columnHeaderBorder"