Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DataGrid GroupRow styles #370

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions SukiUI.Demo/Features/ControlsLibrary/CollectionsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@
MaxHeight="200"
CanUserResizeColumns="{Binding IsDataGridColumnsResizable}"
ItemsSource="{Binding DataGridContent}">
<DataGrid.Styles>
<Style Selector="DataGridRowGroupHeader">
<Setter Property="IsItemCountVisible" Value="True" />
</Style>
</DataGrid.Styles>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding StringColumn}" Header="String" />
<DataGridTextColumn Binding="{Binding IntColumn}"

Header="Int" />
<DataGridCheckBoxColumn Binding="{Binding BoolColumn}"

Header="Bool" />

<DataGridTextColumn Binding="{Binding StringColumn, DataType=controlsLibrary:DataGridContentViewModel}" Header="String" />
<DataGridTextColumn Binding="{Binding IntColumn, DataType=controlsLibrary:DataGridContentViewModel}" Header="Int" />
<DataGridCheckBoxColumn Binding="{Binding BoolColumn, DataType=controlsLibrary:DataGridContentViewModel}" Header="Bool" />
<DataGridTextColumn Binding="{Binding Group, DataType=controlsLibrary:DataGridContentViewModel}" Header="Group" />
</DataGrid.Columns>
</DataGrid>
</showMeTheXaml:XamlDisplay>
Expand Down
9 changes: 6 additions & 3 deletions SukiUI.Demo/Features/ControlsLibrary/CollectionsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ namespace SukiUI.Demo.Features.ControlsLibrary;
public partial class CollectionsViewModel : DemoPageBase
{
public AvaloniaList<string> SimpleContent { get; } = [];
public AvaloniaList<DataGridContentViewModel> DataGridContent { get; } = [];
public DataGridCollectionView DataGridContent { get; }
public AvaloniaList<Node> TreeViewContent { get; } = [];
[ObservableProperty] private string _selectedSimpleContent;
[ObservableProperty] private bool _isDataGridColumnsResizable;

public CollectionsViewModel() : base("Collections", MaterialIconKind.ListBox)
{
SimpleContent.AddRange(Enumerable.Range(1, 50).Select(x => $"Option {x}"));
DataGridContent.AddRange(Enumerable.Range(1, 50).Select(x => new DataGridContentViewModel(x)));
DataGridContent = new DataGridCollectionView(Enumerable.Range(1, 50).Select(x => new DataGridContentViewModel(x)));
DataGridContent.GroupDescriptions.Add(new DataGridPathGroupDescription("Group"));
//DataGridContent.AddRange(Enumerable.Range(1, 50).Select(x => new DataGridContentViewModel(x)));
SelectedSimpleContent = SimpleContent.First();
TreeViewContent.AddRange(
Enumerable.Range(1, 10).Select(x => new Node($"Outer {x}",
Expand All @@ -30,8 +32,9 @@ public CollectionsViewModel() : base("Collections", MaterialIconKind.ListBox)
public partial class DataGridContentViewModel(int value) : ObservableObject
{
[ObservableProperty] private string _stringColumn = $"Content {value}";
[ObservableProperty] private int _intColumn = value;
[ObservableProperty] [NotifyPropertyChangedFor(nameof(Group))] private int _intColumn = value;
[ObservableProperty] private bool _boolColumn = Random.Shared.Next(0, 2) == 0;
public string Group => IntColumn % 2 == 0 ? "Even" : "Odd";
}

public partial class Node(string value, IEnumerable<Node>? subNodes = null) : ObservableObject
Expand Down
14 changes: 10 additions & 4 deletions SukiUI/Theme/DataGridStyle.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
</Style>

<Style Selector="DataGridRowGroupHeader">
<Setter Property="Background" Value="{DynamicResource ThemeControlMidHighBrush}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Height" Value="20" />
<Setter Property="Template">
<ControlTemplate>
Expand All @@ -236,6 +236,8 @@
<ToggleButton Name="ExpanderButton"
Grid.Row="1"
Grid.Column="2"
FontWeight="DemiBold"
Foreground="{DynamicResource SukiText}"
Margin="2,0,0,0" />

<StackPanel Grid.Row="1"
Expand All @@ -245,18 +247,22 @@
Orientation="Horizontal">
<TextBlock Name="PropertyNameElement"
Margin="4,0,0,0"
FontWeight="DemiBold"
IsVisible="{TemplateBinding IsPropertyNameVisible}" />
<TextBlock Margin="4,0,0,0" Text="{Binding Key}" />
<TextBlock Margin="4,0,0,0"
FontWeight="DemiBold"
Text="{Binding Key}" />
<TextBlock Name="ItemCountElement"
Margin="4,0,0,0"
FontWeight="DemiBold"
IsVisible="{TemplateBinding IsItemCountVisible}" />
</StackPanel>

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

</DataGridFrozenGrid>
</ControlTemplate>
Expand All @@ -274,7 +280,7 @@
<Path HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="M 0 2 L 4 6 L 0 10 Z"
Fill="Transparent" />
Fill="{DynamicResource SukiText}" />
</Border>
</ControlTemplate>
</Setter>
Expand Down