Files
ShrlAlgoToolkit/AntDesignWPF/Controls/DataGrid.xaml
2025-07-31 20:12:24 +08:00

93 lines
5.4 KiB
XML

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!--<SolidColorBrush x:Key="AntDesign.Brush.Primary" Color="#1890ff"/>-->
<!--<SolidColorBrush x:Key="AntDesign.Brush.BorderPrimary" Color="#e8e8e8"/>-->
<!--<SolidColorBrush x:Key="AntDesign.Brush.FillPrimary" Color="#fafafa"/>-->
<!--<SolidColorBrush x:Key="AntDesign.Brush.FillSecondary" Color="#e6f7ff"/>-->
<!--<SolidColorBrush x:Key="AntDesign.Brush.FillTertiary" Color="#f9f9f9"/>-->
<!--<SolidColorBrush x:Key="AntDesign.Brush.TextPrimary" Color="#333333"/>-->
<!--<SolidColorBrush x:Key="AntDesign.Brush.TextSecondary" Color="#555555"/>-->
<Style x:Key="AntDesignDataGridCellStyle" TargetType="DataGridCell">
<Setter Property="Padding" Value="12,8"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border Padding="{TemplateBinding Padding}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="True">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource AntDesign.Brush.FillSecondary}"/>
<Setter Property="Foreground" Value="{DynamicResource AntDesign.Brush.TextPrimary}"/>
</Trigger>
</Style.Triggers>
</Style>
<!-- DataGridColumnHeader 样式 -->
<Style x:Key="AntDesignDataGridColumnHeaderStyle" TargetType="DataGridColumnHeader">
<Setter Property="Background" Value="{DynamicResource AntDesign.Brush.FillTertiary}"/>
<Setter Property="Foreground" Value="{DynamicResource AntDesign.Brush.TextSecondary}"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Padding" Value="12,8"/>
<Setter Property="BorderThickness" Value="0,0,1,1"/>
<Setter Property="BorderBrush" Value="{DynamicResource AntDesign.Brush.BorderPrimary}"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
</Style>
<!-- DataGridRow 样式 -->
<Style x:Key="AntDesignDataGridRowStyle" TargetType="DataGridRow">
<Setter Property="Background" Value="White"/>
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
<Setter Property="ValidationErrorTemplate">
<Setter.Value>
<ControlTemplate>
<TextBlock Margin="2,0,0,0" VerticalAlignment="Center" Foreground="Red" Text="!"/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<!-- 鼠标悬停效果 -->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{DynamicResource AntDesign.Brush.FillSecondary}"/>
</Trigger>
<!-- 选中行效果 -->
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource AntDesign.Brush.FillSecondary}"/>
</Trigger>
</Style.Triggers>
</Style>
<!-- 整体 DataGrid 样式 -->
<Style x:Key="Ant.DataGrid" TargetType="DataGrid">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{DynamicResource AntDesign.Brush.TextPrimary}"/>
<Setter Property="BorderBrush" Value="{DynamicResource AntDesign.Brush.BorderPrimary}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="HeadersVisibility" Value="Column"/>
<Setter Property="GridLinesVisibility" Value="Horizontal"/>
<Setter Property="HorizontalGridLinesBrush" Value="{DynamicResource AntDesign.Brush.BorderPrimary}"/>
<Setter Property="RowStyle" Value="{StaticResource AntDesignDataGridRowStyle}"/>
<Setter Property="CellStyle" Value="{StaticResource AntDesignDataGridCellStyle}"/>
<Setter Property="ColumnHeaderStyle" Value="{StaticResource AntDesignDataGridColumnHeaderStyle}"/>
<Setter Property="AlternatingRowBackground" Value="{DynamicResource AntDesign.Brush.FillTertiary}"/>
<!--<Setter Property="AutoGenerateColumns" Value="False" />-->
<Setter Property="CanUserAddRows" Value="False"/>
<Setter Property="CanUserDeleteRows" Value="False"/>
<Setter Property="CanUserResizeRows" Value="False"/>
<Setter Property="SelectionMode" Value="Single"/>
<Setter Property="SelectionUnit" Value="FullRow"/>
</Style>
<Style BasedOn="{StaticResource Ant.DataGrid}" TargetType="{x:Type DataGrid}" />
</ResourceDictionary>