Created
May 27, 2022 11:12
-
-
Save gekka/5017921c261ea035abd012f7213708df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="WpfApp39.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:local="clr-namespace:WpfApp39" | |
mc:Ignorable="d" | |
Title="MainWindow" Height="450" Width="600"> | |
<Window.Resources> | |
<Style TargetType="{x:Type Line}" x:Key="DataGridRow.Line"> | |
<Setter Property="Visibility" Value="Collapsed" /> | |
<Setter Property="Stroke" Value="Red" /> | |
<Setter Property="StrokeThickness" Value="2" /> | |
<Setter Property="VerticalAlignment" Value="Center" /> | |
</Style> | |
<Style TargetType="{x:Type DataGridRow}" x:Key="dataGridRowStyle"> | |
<Setter Property="Template"> | |
<Setter.Value> | |
<ControlTemplate TargetType="{x:Type DataGridRow}"> | |
<Border x:Name="DGR_Border" BorderBrush="{TemplateBinding BorderBrush}" | |
BorderThickness="{TemplateBinding BorderThickness}" | |
Background="{TemplateBinding Background}" | |
SnapsToDevicePixels="True"> | |
<SelectiveScrollingGrid> | |
<SelectiveScrollingGrid.ColumnDefinitions> | |
<ColumnDefinition Width="Auto"/> | |
<ColumnDefinition Width="*"/> | |
</SelectiveScrollingGrid.ColumnDefinitions> | |
<SelectiveScrollingGrid.RowDefinitions> | |
<RowDefinition Height="*"/> | |
<RowDefinition Height="Auto"/> | |
</SelectiveScrollingGrid.RowDefinitions> | |
<DataGridCellsPresenter x:Name="cellsPresenter" Grid.Column="1" | |
ItemsPanel="{TemplateBinding ItemsPanel}" | |
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> | |
<DataGridDetailsPresenter Grid.Column="1" Grid.Row="1" | |
SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen, ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical}, Converter={x:Static DataGrid.RowDetailsScrollingConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" | |
Visibility="{TemplateBinding DetailsVisibility}"/> | |
<!-- DataGridRowの中にLineを配置 --> | |
<Line x:Name="line" Grid.Column="1" Style="{DynamicResource ResourceKey=DataGridRow.Line}" | |
X2="{Binding ElementName=cellsPresenter,Path=ActualWidth}" /> | |
<DataGridRowHeader Grid.RowSpan="2" | |
SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical" | |
Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Row}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/> | |
</SelectiveScrollingGrid> | |
</Border> | |
</ControlTemplate> | |
</Setter.Value> | |
</Setter> | |
</Style> | |
</Window.Resources> | |
<Grid> | |
<DataGrid ItemContainerStyle="{StaticResource ResourceKey=dataGridRowStyle}" | |
ItemsSource="{Binding}" DataContext="ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
HeadersVisibility="All" RowHeaderWidth="30" CanUserResizeColumns="True" > | |
<DataGrid.Resources> | |
<Style TargetType="{x:Type Line}" x:Key="DataGridRow.Line" BasedOn="{StaticResource ResourceKey=DataGridRow.Line}"> | |
<Style.Triggers> | |
<DataTrigger Binding="{Binding}" Value="A" > | |
<Setter Property="Visibility" Value="Visible" /> | |
</DataTrigger> | |
<DataTrigger Binding="{Binding}" Value="G" > | |
<Setter Property="Visibility" Value="Visible" /> | |
<Setter Property="Stroke" Value="#7F00FF00" /> | |
</DataTrigger> | |
<DataTrigger Binding="{Binding}" Value="B" > | |
<Setter Property="Visibility" Value="Visible" /> | |
<Setter Property="Stroke" Value="#7F0000FF" /> | |
<Setter Property="VerticalAlignment" Value="Bottom" /> | |
<Setter Property="Margin" Value="0,0,0,3" /> | |
<!--<Setter Property="X1" Value="50" />--> | |
</DataTrigger> | |
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=IsMouseOver}" Value="True"> | |
<Setter Property="StrokeThickness" Value="5" /> | |
</DataTrigger> | |
</Style.Triggers> | |
</Style> | |
</DataGrid.Resources> | |
<DataGrid.Columns> | |
<DataGridTextColumn Header="Column1" IsReadOnly="true" Binding="{Binding Mode=OneWay}" /> | |
<DataGridTextColumn Header="Column2" IsReadOnly="true" Binding="{Binding Mode=OneWay}" /> | |
<DataGridTextColumn Header="Column3" IsReadOnly="true" Binding="{Binding Mode=OneWay}" Width="500"/> | |
<DataGridTextColumn Header="Column4" IsReadOnly="true" Binding="{Binding Mode=OneWay}" /> | |
<DataGridTextColumn Header="Column5" IsReadOnly="true" Binding="{Binding Mode=OneWay}" /> | |
</DataGrid.Columns> | |
</DataGrid> | |
</Grid> | |
</Window> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment