Skip to content

Commit

Permalink
Add RowBackground support for DataGridRow. #293
Browse files Browse the repository at this point in the history
  • Loading branch information
SKProCH committed Sep 17, 2023
1 parent f5826bc commit 8ff85cf
Showing 1 changed file with 75 additions and 68 deletions.
143 changes: 75 additions & 68 deletions Material.Avalonia.DataGrid/DataGrid.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
</Styles.Resources>

<Style Selector="DataGridCell">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Background" Value="Transparent" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="Padding" Value="16,0"/>
<Setter Property="Padding" Value="16,0" />
<Setter Property="Template">
<ControlTemplate>
<Grid ColumnDefinitions="*,Auto"
Expand All @@ -20,27 +20,27 @@
Margin="{TemplateBinding Padding}"
TextBlock.Foreground="{TemplateBinding Foreground}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Grid>
</ControlTemplate>
</Setter>
</Style>

<Style Selector="DataGridCell TextBlock">
<Setter Property="Height" Value="NaN"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Height" Value="NaN" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontSize" Value="14" />
<Setter Property="FontWeight" Value="Regular" />
</Style>

<Style Selector="DataGridColumnHeader">
<Setter Property="MinHeight" Value="56"/>
<Setter Property="MinHeight" Value="56" />
<Setter Property="Foreground" Value="{DynamicResource MaterialColumnHeaderBrush}" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="SeparatorBrush" Value="{DynamicResource MaterialDividerBrush}" />
<Setter Property="Padding" Value="16,0" />
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<ControlTemplate>
<Grid ColumnDefinitions="*,Auto"
Expand All @@ -50,7 +50,7 @@
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}">
<ContentPresenter Content="{TemplateBinding Content}"/>
<ContentPresenter Content="{TemplateBinding Content}" />

<Path Name="SortIcon"
Grid.Column="1"
Expand All @@ -60,7 +60,7 @@
Stretch="Uniform"
Width="8"
Margin="4,0,0,0"
Data="F1 M -5.215,6.099L 5.215,6.099L 0,0L -5.215,6.099 Z "/>
Data="F1 M -5.215,6.099L 5.215,6.099L 0,0L -5.215,6.099 Z " />

</Grid>

Expand All @@ -76,17 +76,17 @@
</Style>

<Style Selector="DataGridColumnHeader TextBlock">
<Setter Property="Height" Value="NaN"/>
<Setter Property="Height" Value="NaN" />
<Setter Property="FontSize" Value="14" />
<Setter Property="FontWeight" Value="Regular" />
</Style>

<Style Selector="DataGridColumnHeader:dragIndicator">
<Setter Property="Opacity" Value="0.5"/>
<Setter Property="Opacity" Value="0.5" />
</Style>

<Style Selector="DataGridColumnHeader /template/ Path#SortIcon">
<Setter Property="IsVisible" Value="False"/>
<Setter Property="IsVisible" Value="False" />
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="0.9" ScaleY="0.9" />
Expand All @@ -95,52 +95,59 @@
</Style>

<Style Selector="DataGridColumnHeader:sortascending /template/ Path#SortIcon">
<Setter Property="IsVisible" Value="True"/>
<Setter Property="IsVisible" Value="True" />
</Style>

<Style Selector="DataGridColumnHeader:sortdescending /template/ Path#SortIcon">
<Setter Property="IsVisible" Value="True"/>
<Setter Property="IsVisible" Value="True" />
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="0.9" ScaleY="-0.9" />
</Setter.Value>
</Setter>
</Style>

<Style Selector="DataGridRow">
<Style Selector="DataGridRow">
<Setter Property="Background" Value="{Binding $parent[DataGrid].RowBackground}" />
<Setter Property="Template">
<ControlTemplate>
<DataGridFrozenGrid Name="PART_Root"
MinHeight="52"
RowDefinitions="*,Auto,Auto"
ColumnDefinitions="Auto,*">

<Rectangle Name="BackgroundRectangle" Grid.RowSpan="2" Grid.ColumnSpan="2"/>

<DataGridRowHeader Grid.RowSpan="3" Name="PART_RowHeader" DataGridFrozenGrid.IsFrozen="True" />
<DataGridCellsPresenter Grid.Column="1" Name="PART_CellsPresenter" DataGridFrozenGrid.IsFrozen="True" />
<DataGridDetailsPresenter Grid.Row="1" Grid.Column="1" Name="PART_DetailsPresenter"/>
<Rectangle Grid.Row="2" Grid.Column="1" Margin="0"
VerticalAlignment="Bottom" Height="1" Name="PART_BottomGridLine"
HorizontalAlignment="Stretch"/>
</DataGridFrozenGrid>
<Border x:Name="RowBorder"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<DataGridFrozenGrid Name="PART_Root"
MinHeight="52"
RowDefinitions="*,Auto,Auto"
ColumnDefinitions="Auto,*">

<Rectangle Name="BackgroundRectangle" Grid.RowSpan="2" Grid.ColumnSpan="2" />

<DataGridRowHeader Grid.RowSpan="3" Name="PART_RowHeader" DataGridFrozenGrid.IsFrozen="True" />
<DataGridCellsPresenter Grid.Column="1" Name="PART_CellsPresenter" DataGridFrozenGrid.IsFrozen="True" />
<DataGridDetailsPresenter Grid.Row="1" Grid.Column="1" Name="PART_DetailsPresenter" />
<Rectangle Grid.Row="2" Grid.Column="1" Margin="0"
VerticalAlignment="Bottom" Height="1" Name="PART_BottomGridLine"
HorizontalAlignment="Stretch" />
</DataGridFrozenGrid>
</Border>
</ControlTemplate>
</Setter>
</Style>

<Style Selector="DataGridRow /template/ Rectangle#BackgroundRectangle">
<Setter Property="IsVisible" Value="False"/>
<Setter Property="IsVisible" Value="False" />
<Setter Property="Fill" Value="{DynamicResource MaterialSelectionBrush}" />
</Style>

<Style Selector="DataGridRow:pointerover /template/ Rectangle#BackgroundRectangle">
<Setter Property="IsVisible" Value="True"/>
<Setter Property="Opacity" Value="0.5"/>
<Setter Property="IsVisible" Value="True" />
<Setter Property="Opacity" Value="0.5" />
</Style>

<Style Selector="DataGridRow:selected /template/ Rectangle#BackgroundRectangle">
<Setter Property="IsVisible" Value="True"/>
<Setter Property="Opacity" Value="1"/>
<Setter Property="IsVisible" Value="True" />
<Setter Property="Opacity" Value="1" />
</Style>

<!--Style Selector="DataGridRow:selected">
Expand All @@ -151,32 +158,32 @@
<Setter Property="Template">
<ControlTemplate>
<Grid Name="PART_Root"
RowDefinitions="*,*,Auto"
ColumnDefinitions="Auto,*" />
RowDefinitions="*,*,Auto"
ColumnDefinitions="Auto,*" />
</ControlTemplate>
</Setter>
</Style>

<Style Selector="DataGridRowGroupHeader">
<Setter Property="Background" Value="{DynamicResource ThemeControlMidHighBrush}" />
<Setter Property="Height" Value="20"/>
<Setter Property="Height" Value="20" />
<Setter Property="Template">
<ControlTemplate>
<DataGridFrozenGrid Name="Root"
Background="{TemplateBinding Background}"
ColumnDefinitions="Auto,Auto,Auto,Auto"
RowDefinitions="Auto,*,Auto">
Background="{TemplateBinding Background}"
ColumnDefinitions="Auto,Auto,Auto,Auto"
RowDefinitions="Auto,*,Auto">

<Rectangle Grid.Column="1" Grid.Row="1" Name="PART_IndentSpacer" />
<ToggleButton Grid.Column="2" Grid.Row="1" Name="PART_ExpanderButton" Margin="2,0,0,0"/>
<ToggleButton Grid.Column="2" Grid.Row="1" Name="PART_ExpanderButton" Margin="2,0,0,0" />

<StackPanel Grid.Column="3" Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,1,0,1">
<TextBlock Name="PART_PropertyNameElement" Margin="4,0,0,0" IsVisible="{TemplateBinding IsPropertyNameVisible}"/>
<TextBlock Name="PART_PropertyNameElement" Margin="4,0,0,0" IsVisible="{TemplateBinding IsPropertyNameVisible}" />
<TextBlock Margin="4,0,0,0" Text="{Binding Key}" />
<TextBlock Name="PART_ItemCountElement" Margin="4,0,0,0" IsVisible="{TemplateBinding IsItemCountVisible}"/>
<TextBlock Name="PART_ItemCountElement" Margin="4,0,0,0" IsVisible="{TemplateBinding IsItemCountVisible}" />
</StackPanel>

<DataGridRowHeader Name="RowHeader" Grid.RowSpan="3" DataGridFrozenGrid.IsFrozen="True"/>
<DataGridRowHeader Name="RowHeader" Grid.RowSpan="3" DataGridFrozenGrid.IsFrozen="True" />

</DataGridFrozenGrid>
</ControlTemplate>
Expand Down Expand Up @@ -205,18 +212,18 @@
<Style Selector="DataGrid">
<Setter Property="RowBackground" Value="Transparent" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="HeadersVisibility" Value="Column" />
<Setter Property="HeadersVisibility" Value="Column" />
<Setter Property="HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="SelectionMode" Value="Extended" />
<Setter Property="GridLinesVisibility" Value="Horizontal"/>
<Setter Property="GridLinesVisibility" Value="Horizontal" />
<Setter Property="HorizontalGridLinesBrush" Value="{DynamicResource MaterialDividerBrush}" />
<Setter Property="VerticalGridLinesBrush" Value="{DynamicResource MaterialDividerBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource MaterialBodyBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource MaterialBodyBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="DropLocationIndicatorTemplate">
<Template>
<Rectangle Fill="{DynamicResource MaterialSelectionBrush}" Width="2"/>
<Rectangle Fill="{DynamicResource MaterialSelectionBrush}" Width="2" />
</Template>
</Setter>
<Setter Property="Template">
Expand All @@ -228,11 +235,11 @@
<Grid RowDefinitions="Auto,*,Auto,Auto" ColumnDefinitions="Auto,*,Auto">

<DataGridColumnHeader Name="PART_TopLeftCornerHeader" Width="22" />
<DataGridColumnHeadersPresenter Name="PART_ColumnHeadersPresenter" Grid.Column="1"/>
<DataGridColumnHeadersPresenter Name="PART_ColumnHeadersPresenter" Grid.Column="1" />

<Separator Grid.ColumnSpan="3" Margin="0"
VerticalAlignment="Bottom" Height="1"
Background="{TemplateBinding BorderBrush}"/>
Background="{TemplateBinding BorderBrush}" />

<DataGridRowsPresenter Name="PART_RowsPresenter" Grid.ColumnSpan="2" Grid.Row="1">
<DataGridRowsPresenter.GestureRecognizers>
Expand All @@ -247,15 +254,15 @@
<Grid Grid.Column="1" Grid.Row="2"
ColumnDefinitions="Auto,*">
<Rectangle Name="PART_FrozenColumnScrollBarSpacer" />
<ScrollBar Name="PART_HorizontalScrollbar" Grid.Column="1"
Classes="Modern" Orientation="Horizontal"/>
<ScrollBar Name="PART_HorizontalScrollbar" Grid.Column="1"
Classes="Modern" Orientation="Horizontal" />
</Grid>
</Grid>
</Border>
</ControlTemplate>
</Setter>
</Style>

<!-- Template for classic scrollbars -->
<Style Selector="DataGrid.ClassicScrollBar">
<Setter Property="Template">
Expand All @@ -267,11 +274,11 @@
<Grid RowDefinitions="Auto,*,Auto,Auto" ColumnDefinitions="Auto,*,Auto">

<DataGridColumnHeader Name="PART_TopLeftCornerHeader" Width="22" />
<DataGridColumnHeadersPresenter Name="PART_ColumnHeadersPresenter" Grid.Column="1"/>
<DataGridColumnHeadersPresenter Name="PART_ColumnHeadersPresenter" Grid.Column="1" />

<Separator Grid.ColumnSpan="3" Margin="0"
VerticalAlignment="Bottom" Height="1"
Background="{TemplateBinding BorderBrush}"/>
Background="{TemplateBinding BorderBrush}" />

<DataGridRowsPresenter Name="PART_RowsPresenter" Grid.ColumnSpan="2" Grid.Row="1">
<DataGridRowsPresenter.GestureRecognizers>
Expand All @@ -285,15 +292,15 @@
<Grid Grid.Column="1" Grid.Row="2"
ColumnDefinitions="Auto,*">
<Rectangle Name="PART_FrozenColumnScrollBarSpacer" />
<ScrollBar Name="PART_HorizontalScrollbar" Grid.Column="1"
<ScrollBar Name="PART_HorizontalScrollbar" Grid.Column="1"
Orientation="Horizontal" />
</Grid>
</Grid>
</Border>
</ControlTemplate>
</Setter>
</Style>

<!-- Template for mini scrollbars -->
<Style Selector="DataGrid.MiniScrollBar">
<Setter Property="Template">
Expand All @@ -305,11 +312,11 @@
<Grid RowDefinitions="Auto,*,Auto,Auto" ColumnDefinitions="Auto,*,Auto">

<DataGridColumnHeader Name="PART_TopLeftCornerHeader" Width="22" />
<DataGridColumnHeadersPresenter Name="PART_ColumnHeadersPresenter" Grid.Column="1"/>
<DataGridColumnHeadersPresenter Name="PART_ColumnHeadersPresenter" Grid.Column="1" />

<Separator Grid.ColumnSpan="3" Margin="0"
VerticalAlignment="Bottom" Height="1"
Background="{TemplateBinding BorderBrush}"/>
Background="{TemplateBinding BorderBrush}" />

<DataGridRowsPresenter Name="PART_RowsPresenter" Grid.ColumnSpan="2" Grid.Row="1">
<DataGridRowsPresenter.GestureRecognizers>
Expand All @@ -319,27 +326,27 @@
<Rectangle Name="PART_BottomRightCorner" Fill="{DynamicResource ThemeControlMidHighBrush}" Grid.Column="2" Grid.Row="2" />
<Rectangle Name="BottomLeftCorner" Fill="{DynamicResource ThemeControlMidHighBrush}" Grid.Row="2" Grid.ColumnSpan="2" />
<ScrollBar Name="PART_VerticalScrollbar" Classes="Mini"
Grid.Column="2" Grid.Row="1"/>
Grid.Column="2" Grid.Row="1" />

<Grid Grid.Column="1" Grid.Row="2"
ColumnDefinitions="Auto,*">
<Rectangle Name="PART_FrozenColumnScrollBarSpacer" />
<ScrollBar Name="PART_HorizontalScrollbar" Grid.Column="1"
Orientation="Horizontal" Classes="Mini"/>
<ScrollBar Name="PART_HorizontalScrollbar" Grid.Column="1"
Orientation="Horizontal" Classes="Mini" />
</Grid>
</Grid>
</Border>
</ControlTemplate>
</Setter>
</Style>

<Style Selector="DataGrid.DisableHoveringScrollBar ScrollBar:horizontal">
<Setter Property="Margin" Value="0" />
<Setter Property="Height" Value="{DynamicResource ScrollBarThickness}" />
</Style>

<Style Selector="DataGrid.DisableHoveringScrollBar ScrollBar:vertical">
<Setter Property="Margin" Value="0" />
<Setter Property="Width" Value="{DynamicResource ScrollBarThickness}" />
</Style>
</Styles>
</Styles>

0 comments on commit 8ff85cf

Please sign in to comment.