【发布时间】:2014-09-28 06:40:30
【问题描述】:
与此问题相关:Style datagrid table - Top left corner。
我有一个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>
奖励:如何在当前只有 1px 边框的行/列标题上获得 2px 边框?
【问题讨论】: