我已經結束了只使用樣式,如果它不是劇烈的,你可以做你想做的事情。如果任何人設法讓DataGridHeaderBorder上的行選擇,請讓我知道! 例如:
<...xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"...>
<BooleanToVisibilityConverter x:Key="bool2VisibilityConverter"/>
<LinearGradientBrush x:Key="RowHeaderBackgroundBrush" EndPoint="0.728,0.5" StartPoint="0.272,0.5">
<GradientStop Color="#FF494949" Offset="0"/>
<GradientStop Color="#FF3E3E3E" Offset="1"/>
<GradientStop Color="#FF494949" Offset="0.50"/>
<GradientStop Color="#FF3E3E3E" Offset="0.50"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="RowHeaderBackgroundBrushMouseOver" EndPoint="0.728,0.5" StartPoint="0.272,0.5">
<GradientStop Color="#FF666666" Offset="0"/>
<GradientStop Color="#FF525252" Offset="1"/>
<GradientStop Color="#FF666666" Offset="0.50"/>
<GradientStop Color="#FF525252" Offset="0.50"/>
</LinearGradientBrush>
<Style x:Key="RowHeaderGripperStyle" TargetType="{x:Type Thumb}">
<Setter Property="Height" Value="8"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Cursor" Value="SizeNS"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="RowHeaderBorder" TargetType="Border">
<Setter Property="Background" Value="{StaticResource RowHeaderBackgroundBrush}" />
<Setter Property="BorderBrush" Value="#FF313131" />
<Setter Property="BorderThickness" Value="0,0,1,1" />
<Setter Property="CornerRadius" Value="0" />
<Setter Property="Margin" Value="0" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource RowHeaderBackgroundBrushMouseOver}"></Setter>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="RowHeaderStyle1" TargetType="DataGridRowHeader">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DataGridRowHeader">
<Grid>
<Microsoft_Windows_Themes:DataGridHeaderBorder IsPressed="{TemplateBinding IsPressed}" Orientation="Horizontal" SeparatorBrush="{TemplateBinding SeparatorBrush}" SeparatorVisibility="{TemplateBinding SeparatorVisibility}" Style="{StaticResource RowHeaderBorder}">
<StackPanel Orientation="Horizontal">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
<Control SnapsToDevicePixels="false" Template="{Binding ValidationErrorTemplate, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}" Visibility="{Binding (Validation.HasError), Converter={StaticResource bool2VisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}"/>
</StackPanel>
</Microsoft_Windows_Themes:DataGridHeaderBorder>
<Thumb x:Name="PART_TopHeaderGripper" Style="{StaticResource RowHeaderGripperStyle}" VerticalAlignment="Top"/>
<Thumb x:Name="PART_BottomHeaderGripper" Style="{StaticResource RowHeaderGripperStyle}" VerticalAlignment="Bottom"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>