Skip to content

Instantly share code, notes, and snippets.

@hqf00342
Created September 4, 2015 03:21
Show Gist options
  • Save hqf00342/199e53c638d2899445aa to your computer and use it in GitHub Desktop.
Save hqf00342/199e53c638d2899445aa to your computer and use it in GitHub Desktop.
Style for wpf Datagrid
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!--DataGrid用のスタイル-->
<Style TargetType="DataGrid">
<!-- Make the border and grid lines a little less imposing -->
<Setter Property="BorderBrush" Value="#DDDDDD" />
<Setter Property="HorizontalGridLinesBrush" Value="#DDDDDD" />
<Setter Property="VerticalGridLinesBrush" Value="#DDDDDD" />
<Setter Property="RowStyle">
<Setter.Value>
<Style TargetType="DataGridRow">
<Style.Triggers>
<!-- Highlight a grid row as the mouse passes over -->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="LightCyan" />
</Trigger>
</Style.Triggers>
</Style>
</Setter.Value>
</Setter>
<Setter Property="CellStyle">
<Setter.Value>
<Style TargetType="DataGridCell">
<Style.Triggers>
<!-- Highlight selected rows -->
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#ff66ccff" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Foreground" Value="Black" />
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Background" Value="#ff66ccff" />
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="Black" />
</Trigger>
</Style.Triggers>
<!-- Add some padding around the contents of a cell -->
<Setter Property="Padding" Value="4,3,4,3" />
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DataGridCell">
<Border Padding="{TemplateBinding Padding}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}">
<ContentPresenter />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="FocusVisualStyle">
<Setter.Value>
<Style TargetType="Control">
<Setter Property="BorderBrush" Value="Transparent" />
</Style>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
@kostanchika
Copy link

tysm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment