wpf 收集的不错的datagrid样式
1 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 2 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 3 <Style TargetType="DataGrid"> 4 <!--网格线颜色--> 5 <Setter Property="CanUserResizeColumns" Value="false"/> 6 <Setter Property="Background" Value="#99CCFF" /> 7 <Setter Property="BorderBrush" Value="#99CCFF" /> 8 <Setter Property="HorizontalGridLinesBrush"> 9 10 <Setter.Value> 11 <SolidColorBrush Color="#99CCFF"/> 12 </Setter.Value> 13 </Setter> 14 <Setter Property="VerticalGridLinesBrush"> 15 <Setter.Value> 16 <SolidColorBrush Color="#99CCFF"/> 17 </Setter.Value> 18 </Setter> 19 </Style> 20 21 <!--标题栏样式--> 22 <!--<Style TargetType="DataGridColumnHeader" > 23 <Setter Property="Width" Value="50"/> 24 <Setter Property="Height" Value="30"/> 25 <Setter Property="FontSize" Value="14" /> 26 <Setter Property="Background" Value="White" /> 27 <Setter Property="FontWeight" Value="Bold"/> 28 </Style>--> 29 30 <Style TargetType="DataGridColumnHeader"> 31 <Setter Property="SnapsToDevicePixels" Value="True" /> 32 <Setter Property="MinWidth" Value="0" /> 33 <Setter Property="MinHeight" Value="28" /> 34 <Setter Property="Foreground" Value="#323433" /> 35 <Setter Property="FontSize" Value="14" /> 36 <Setter Property="Cursor" Value="Hand" /> 37 <Setter Property="Template"> 38 <Setter.Value> 39 <ControlTemplate TargetType="DataGridColumnHeader"> 40 <Border x:Name="BackgroundBorder" BorderThickness="0,1,0,1" 41 BorderBrush="#99CCFF" 42 Width="Auto"> 43 <Grid > 44 <Grid.ColumnDefinitions> 45 <ColumnDefinition Width="*" /> 46 </Grid.ColumnDefinitions> 47 <ContentPresenter Margin="0,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Center"/> 48 <Path x:Name="SortArrow" Visibility="Collapsed" Data="M0,0 L1,0 0.5,1 z" Stretch="Fill" Grid.Column="2" Width="8" Height="6" Fill="White" Margin="0,0,50,0" 49 VerticalAlignment="Center" RenderTransformOrigin="1,1" /> 50 <Rectangle Width="1" Fill="#FF7EAFE0" HorizontalAlignment="Right" Grid.ColumnSpan="1" /> 51 <!--<TextBlock Background="Red"> 52 <ContentPresenter></ContentPresenter></TextBlock>--> 53 </Grid> 54 </Border> 55 </ControlTemplate> 56 </Setter.Value> 57 </Setter> 58 <Setter Property="Height" Value="25"/> 59 </Style> 60 <!--行样式触发--> 61 <!--背景色改变必须先设置cellStyle 因为cellStyle会覆盖rowStyle样式--> 62 <Style TargetType="DataGridRow"> 63 <Setter Property="Background" Value="#F2F2F2" /> 64 <Setter Property="Height" Value="25"/> 65 <Setter Property="Foreground" Value="Black" /> 66 <Style.Triggers> 67 <!--隔行换色--> 68 <Trigger Property="AlternationIndex" Value="0" > 69 <Setter Property="Background" Value="#e7e7e7" /> 70 </Trigger> 71 <Trigger Property="AlternationIndex" Value="1" > 72 <Setter Property="Background" Value="#f2f2f2" /> 73 </Trigger> 74 75 <Trigger Property="IsMouseOver" Value="True"> 76 <Setter Property="Background" Value="LightGray"/> 77 <!--<Setter Property="Foreground" Value="White"/>--> 78 </Trigger> 79 80 <Trigger Property="IsSelected" Value="True"> 81 <Setter Property="Foreground" Value="Black"/> 82 </Trigger> 83 </Style.Triggers> 84 </Style> 85 86 <!--单元格样式触发--> 87 <Style TargetType="DataGridCell"> 88 <Setter Property="Template"> 89 <Setter.Value> 90 <ControlTemplate TargetType="DataGridCell"> 91 <TextBlock TextAlignment="Center" VerticalAlignment="Center" > 92 <ContentPresenter /> 93 </TextBlock> 94 </ControlTemplate> 95 </Setter.Value> 96 </Setter> 97 <Style.Triggers> 98 <Trigger Property="IsSelected" Value="True"> 99 <!--<Setter Property="Background" Value="White"/> 100 <Setter Property="BorderThickness" Value="0"/>--> 101 <Setter Property="Foreground" Value="Black"/> 102 </Trigger> 103 </Style.Triggers> 104 </Style> 105 106 </ResourceDictionary>