resources/xaml/styles/DataGridStyle.xaml
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style x:Key="ColumnHeaderGripperStyle" TargetType="Thumb"> <Setter Property="Width" Value="8"/> <Setter Property="Background" Value="Transparent"/> <Setter Property="Cursor" Value="SizeWE"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Thumb"> <Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"/> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ModernDataGridStyle" TargetType="DataGrid"> <Setter Property="Background" Value="{DynamicResource ControlBackgroundBrush}"/> <Setter Property="Foreground" Value="{DynamicResource ControlForegroundBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="RowBackground" Value="{DynamicResource WindowBackgroundBrush}"/> <Setter Property="AlternatingRowBackground" Value="{DynamicResource GridAlternatingRowBrush}"/> <Setter Property="AlternationCount" Value="2"/> <Setter Property="HorizontalGridLinesBrush" Value="{DynamicResource GridLineBrush}"/> <Setter Property="VerticalGridLinesBrush" Value="{DynamicResource GridLineBrush}"/> <Setter Property="ColumnHeaderStyle" Value="{DynamicResource ModernDataGridColumnHeaderStyle}"/> <Setter Property="CellStyle" Value="{DynamicResource ModernDataGridCellStyle}"/> <Setter Property="RowStyle" Value="{DynamicResource ModernDataGridRowStyle}"/> <Setter Property="GridLinesVisibility" Value="Horizontal"/> <Setter Property="HeadersVisibility" Value="Column"/> <Setter Property="AutoGenerateColumns" Value="True"/> <Setter Property="CanUserResizeColumns" Value="True"/> <Setter Property="CanUserSortColumns" Value="True"/> <Setter Property="IsReadOnly" Value="True"/> <Setter Property="SelectionMode" Value="Single"/> <Setter Property="FontFamily" Value="Segoe UI"/> <Setter Property="FontSize" Value="12"/> </Style> <Style x:Key="ModernDataGridColumnHeaderStyle" TargetType="DataGridColumnHeader"> <Setter Property="Background" Value="{DynamicResource GridHeaderBackgroundBrush}"/> <Setter Property="Foreground" Value="{DynamicResource GridHeaderForegroundBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/> <Setter Property="BorderThickness" Value="0,0,1,1"/> <Setter Property="Padding" Value="12,8,12,8"/> <Setter Property="FontWeight" Value="SemiBold"/> <Setter Property="HorizontalContentAlignment" Value="Left"/> <Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="DataGridColumnHeader"> <Grid> <Border x:Name="HeaderBorder" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <ContentPresenter Grid.Column="0" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> <Path x:Name="SortArrow" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center" Width="8" Height="4" Margin="4,0,0,0" Stretch="Fill" Opacity="0.5" Fill="{TemplateBinding Foreground}" RenderTransformOrigin="0.5,0.5" Visibility="Collapsed" Data="M0,0 L10,0 L5,5 z"> <Path.RenderTransform> <TransformGroup> <ScaleTransform/> <SkewTransform/> <RotateTransform/> <TranslateTransform/> </TransformGroup> </Path.RenderTransform> </Path> </Grid> </Border> <Thumb x:Name="PART_LeftHeaderGripper" HorizontalAlignment="Left" Style="{StaticResource ColumnHeaderGripperStyle}"/> <Thumb x:Name="PART_RightHeaderGripper" HorizontalAlignment="Right" Style="{StaticResource ColumnHeaderGripperStyle}"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="SortDirection" Value="Ascending"> <Setter TargetName="SortArrow" Property="Visibility" Value="Visible"/> <Setter TargetName="SortArrow" Property="RenderTransform"> <Setter.Value> <RotateTransform Angle="180"/> </Setter.Value> </Setter> </Trigger> <Trigger Property="SortDirection" Value="Descending"> <Setter TargetName="SortArrow" Property="Visibility" Value="Visible"/> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="HeaderBorder" Property="Background" Value="{DynamicResource AccentHeaderBackgroundBrush}"/> <Setter Property="Foreground" Value="{DynamicResource AccentHeaderForegroundBrush}"/> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter TargetName="HeaderBorder" Property="Background" Value="{DynamicResource AccentBrush}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="ModernDataGridCellStyle" TargetType="DataGridCell"> <Setter Property="Background" Value="Transparent"/> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Padding" Value="12,6,12,6"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="DataGridCell"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"> <ContentPresenter VerticalAlignment="Center"/> </Border> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="Background" Value="{DynamicResource AccentBrush}"/> <Setter Property="Foreground" Value="{DynamicResource SelectionTextBrush}"/> </Trigger> </Style.Triggers> </Style> <!-- DataGridRow style with hover effect and alternating backgrounds --> <Style x:Key="ModernDataGridRowStyle" TargetType="DataGridRow"> <Setter Property="SnapsToDevicePixels" Value="True"/> <Setter Property="Background" Value="{DynamicResource WindowBackgroundBrush}"/> <Setter Property="BorderThickness" Value="0,0,0,1"/> <Setter Property="BorderBrush" Value="{DynamicResource GridLineBrush}"/> <Style.Triggers> <!-- Alternating row background using AlternationIndex --> <Trigger Property="AlternationIndex" Value="1"> <Setter Property="Background" Value="{DynamicResource GridAlternatingRowBrush}"/> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="{DynamicResource ItemHoverBrush}"/> </Trigger> <Trigger Property="IsSelected" Value="True"> <Setter Property="Background" Value="{DynamicResource AccentBrush}"/> </Trigger> </Style.Triggers> </Style> </ResourceDictionary> |