-
Notifications
You must be signed in to change notification settings - Fork 105
Add Material.Avalonia.TreeDataGrid project with TreeDataGrid styles
#467
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
664b937
Add `Material.Avalonia.TreeDataGrid` project with TreeDataGrid styles…
5dde212
Fix: Added fixed width to `PART_ExpanderPanel` to prevent toggle butt…
c1b5ea7
Refactor: Split `TreeDataGrid` styles into separate axaml files for b…
ee43076
Add TreeDataGridStyles auto importing
SKProCH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
28 changes: 28 additions & 0 deletions
28
...rial.Avalonia.TreeDataGrid/Converters/TreeDataGridSourceColumnAlignmentToDockConverter.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Globalization; | ||
| using Avalonia.Controls; | ||
| using Avalonia.Data.Converters; | ||
| using Avalonia.Media; | ||
|
|
||
| namespace Material.Avalonia.TreeDataGrid.Converters; | ||
|
|
||
| public sealed class TreeDataGridSourceColumnAlignmentToDockConverter : IMultiValueConverter | ||
| { | ||
| public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture) | ||
| { | ||
| if (values[0] is not ITreeDataGridSource source || | ||
| values[1] is not int columnIndex || | ||
| columnIndex < 0 || | ||
| columnIndex >= source.Columns.Count) | ||
| return Dock.Left; | ||
|
|
||
| var column = source.Columns[columnIndex]; | ||
| var align = TextColumnAlignmentProvider.GetTextAlignment(column); | ||
|
|
||
| return align == TextAlignment.Right ? Dock.Right : Dock.Left; | ||
| } | ||
|
|
||
| public object[] ConvertBack(object? value, Type[] targetTypes, object? parameter, CultureInfo culture) | ||
| => throw new NotSupportedException(); | ||
| } |
30 changes: 30 additions & 0 deletions
30
Material.Avalonia.TreeDataGrid/Material.Avalonia.TreeDataGrid.csproj
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <Description>TreeDataGrid styles library of Material.Avalonia.</Description> | ||
| <PackageTags>avalonia xaml material design theme treedatagrid colour color ui ux material-design google-material</PackageTags> | ||
| <PackageIcon>FavIcon.png</PackageIcon> | ||
|
|
||
| <TargetFrameworks>net8.0</TargetFrameworks> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Include="../wiki/FavIcon.png" Pack="true" PackagePath="/" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Avalonia.Controls.TreeDataGrid" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Material.Avalonia\Material.Avalonia.csproj"/> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Content Include="*.props"> | ||
| <Pack>true</Pack> | ||
| <PackagePath>build\;buildTransitive\</PackagePath> | ||
| </Content> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
7 changes: 7 additions & 0 deletions
7
Material.Avalonia.TreeDataGrid/Material.Avalonia.TreeDataGrid.props
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <ItemGroup> | ||
| <RuntimeHostConfigurationOption Include="MaterialThemeIncludeTreeDataGrid" Value="true"/> | ||
SKProCH marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <!--To exclude this library from trimming--> | ||
| <TrimmerRootAssembly Include="Material.Avalonia.TreeDataGrid" RootMode="library"/> | ||
| </ItemGroup> | ||
| </Project> | ||
18 changes: 18 additions & 0 deletions
18
Material.Avalonia.TreeDataGrid/MaterialTreeDataGridStyles.axaml
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <treeDataGrid:MaterialTreeDataGridStyles xmlns="https://github.com/avaloniaui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
| xmlns:treeDataGrid="clr-namespace:Material.Avalonia.TreeDataGrid" | ||
| x:Class="Material.Avalonia.TreeDataGrid.MaterialTreeDataGridStyles"> | ||
| <treeDataGrid:MaterialTreeDataGridStyles.Resources> | ||
| <ResourceDictionary> | ||
| <ResourceDictionary.MergedDictionaries> | ||
| <ResourceInclude Source="avares://Material.Avalonia.TreeDataGrid/TreeDataGridCheckBoxCell.axaml" /> | ||
| <ResourceInclude Source="avares://Material.Avalonia.TreeDataGrid/TreeDataGridExpanderCell.axaml" /> | ||
| <ResourceInclude Source="avares://Material.Avalonia.TreeDataGrid/TreeDataGridTemplateCell.axaml" /> | ||
| <ResourceInclude Source="avares://Material.Avalonia.TreeDataGrid/TreeDataGridTextCell.axaml" /> | ||
| <ResourceInclude Source="avares://Material.Avalonia.TreeDataGrid/TreeDataGridRow.axaml" /> | ||
| <ResourceInclude Source="avares://Material.Avalonia.TreeDataGrid/TreeDataGridColumnHeader.axaml" /> | ||
| <ResourceInclude Source="avares://Material.Avalonia.TreeDataGrid/TreeDataGrid.axaml" /> | ||
| </ResourceDictionary.MergedDictionaries> | ||
| </ResourceDictionary> | ||
| </treeDataGrid:MaterialTreeDataGridStyles.Resources> | ||
| </treeDataGrid:MaterialTreeDataGridStyles> |
4 changes: 4 additions & 0 deletions
4
Material.Avalonia.TreeDataGrid/MaterialTreeDataGridStyles.axaml.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| namespace Material.Avalonia.TreeDataGrid; | ||
|
|
||
| public class MaterialTreeDataGridStyles : global::Avalonia.Styling.Styles { | ||
| } |
40 changes: 40 additions & 0 deletions
40
Material.Avalonia.TreeDataGrid/TextColumnAlignmentProvider.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| using System; | ||
| using System.Collections.Concurrent; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Reflection; | ||
| using Avalonia.Controls.Models.TreeDataGrid; | ||
| using Avalonia.Media; | ||
|
|
||
| namespace Material.Avalonia.TreeDataGrid; | ||
|
|
||
| internal static class TextColumnAlignmentProvider | ||
| { | ||
| private static readonly ConcurrentDictionary<Type, Func<object, TextAlignment?>> _cache = new(); | ||
|
|
||
| public static TextAlignment? GetTextAlignment(object column) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(column); | ||
|
|
||
| var colType = column.GetType(); | ||
| if (!colType.IsGenericType | ||
| || colType.GetGenericTypeDefinition() != typeof(TextColumn<,>)) | ||
| return null; | ||
|
|
||
| var getter = _cache.GetOrAdd(colType, BuildGetter); | ||
| return getter(column); | ||
| } | ||
|
|
||
| [UnconditionalSuppressMessage("AOT", "IL3050:Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.", Justification = "<Pending>")] | ||
| private static Func<object, TextAlignment?> BuildGetter(Type closedColumnType) | ||
| { | ||
| var helperMethod = typeof(TextColumnHelper) | ||
| .GetMethod(nameof(TextColumnHelper.GetTextAlignmentGeneric), | ||
| BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)!; | ||
|
|
||
| var genArgs = closedColumnType.GetGenericArguments(); | ||
| var closedMethod = helperMethod.MakeGenericMethod(genArgs); | ||
|
|
||
| return (Func<object, TextAlignment?>)closedMethod | ||
| .CreateDelegate(typeof(Func<object, TextAlignment?>)); | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using Avalonia.Controls.Models.TreeDataGrid; | ||
| using Avalonia.Media; | ||
|
|
||
| namespace Material.Avalonia.TreeDataGrid; | ||
|
|
||
| internal static class TextColumnHelper | ||
| { | ||
| public static TextAlignment? GetTextAlignmentGeneric<TModel, TValue>(object column) | ||
| where TModel : class | ||
| { | ||
| var typed = (TextColumn<TModel, TValue>)column; | ||
| return typed.Options.TextAlignment; | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| <ResourceDictionary xmlns="https://github.com/avaloniaui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> | ||
| <ControlTheme x:Key="{x:Type TreeDataGrid}" TargetType="TreeDataGrid"> | ||
SKProCH marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <Setter Property="CornerRadius" Value="4" /> | ||
| <Setter Property="BorderBrush" Value="{DynamicResource MaterialDividerBrush}" /> | ||
| <Setter Property="Template"> | ||
| <ControlTemplate> | ||
| <Border x:Name="RootBorder" | ||
| Background="{TemplateBinding Background}" | ||
| BorderBrush="{TemplateBinding BorderBrush}" | ||
| BorderThickness="{TemplateBinding BorderThickness}" | ||
| CornerRadius="{TemplateBinding CornerRadius}"> | ||
| <DockPanel> | ||
| <ScrollViewer x:Name="PART_HeaderScrollViewer" | ||
| DockPanel.Dock="Top" | ||
| IsVisible="{TemplateBinding ShowColumnHeaders}" | ||
| HorizontalScrollBarVisibility="Hidden" | ||
| VerticalScrollBarVisibility="Disabled" | ||
| BringIntoViewOnFocusChange="{TemplateBinding (ScrollViewer.BringIntoViewOnFocusChange)}"> | ||
| <Border x:Name="ColumnHeadersPresenterBorder"> | ||
| <TreeDataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" | ||
| ElementFactory="{TemplateBinding ElementFactory}" | ||
| Items="{TemplateBinding Columns}" /> | ||
| </Border> | ||
| </ScrollViewer> | ||
| <ScrollViewer x:Name="PART_ScrollViewer" | ||
| HorizontalScrollBarVisibility="Auto" | ||
| BringIntoViewOnFocusChange="{TemplateBinding (ScrollViewer.BringIntoViewOnFocusChange)}"> | ||
| <TreeDataGridRowsPresenter x:Name="PART_RowsPresenter" | ||
| Columns="{TemplateBinding Columns}" | ||
| ElementFactory="{TemplateBinding ElementFactory}" | ||
| Items="{TemplateBinding Rows}" /> | ||
| </ScrollViewer> | ||
| </DockPanel> | ||
| </Border> | ||
| </ControlTemplate> | ||
| </Setter> | ||
|
|
||
| <Style Selector="^ /template/ Border#ColumnHeadersPresenterBorder"> | ||
| <Setter Property="BorderThickness" Value="0 0 0 1" /> | ||
| <Setter Property="BorderBrush" Value="{TemplateBinding BorderBrush}" /> | ||
| </Style> | ||
|
|
||
| <Style Selector="^ /template/ ScrollViewer"> | ||
| <Setter Property="Theme" Value="{StaticResource MaterialModernScrollViewer}" /> | ||
| </Style> | ||
|
|
||
| <!-- Template for classic scrollviewers --> | ||
| <Style Selector="^.ClassicScrollViewer /template/ ScrollViewer"> | ||
| <Setter Property="Theme" Value="{StaticResource MaterialScrollViewer}" /> | ||
| </Style> | ||
|
|
||
| <Style Selector="^.DisableHoveringScrollViewer /template/ ScrollViewer"> | ||
| <Setter Property="Margin" Value="0" /> | ||
| <Style Selector="^:horizontal"> | ||
| <Setter Property="Height" Value="{DynamicResource ScrollBarThickness}" /> | ||
| </Style> | ||
| <Style Selector="^:vertical"> | ||
| <Setter Property="Height" Value="{DynamicResource ScrollBarThickness}" /> | ||
| </Style> | ||
| </Style> | ||
| </ControlTheme> | ||
| </ResourceDictionary> | ||
37 changes: 37 additions & 0 deletions
37
Material.Avalonia.TreeDataGrid/TreeDataGridCheckBoxCell.axaml
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <ResourceDictionary xmlns="https://github.com/avaloniaui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> | ||
| <ControlTheme x:Key="{x:Type TreeDataGridCheckBoxCell}" TargetType="TreeDataGridCheckBoxCell"> | ||
| <Setter Property="Template"> | ||
| <ControlTemplate> | ||
| <Border x:Name="CellBorder" | ||
| Background="{TemplateBinding Background}" | ||
| BorderBrush="{TemplateBinding BorderBrush}" | ||
| BorderThickness="{TemplateBinding BorderThickness}" | ||
| CornerRadius="{TemplateBinding CornerRadius}" | ||
| Padding="{TemplateBinding Padding}"> | ||
| <CheckBox x:Name="PART_CheckBox" | ||
| IsChecked="{TemplateBinding Value, Mode=TwoWay}" | ||
| IsEnabled="{Binding !IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" | ||
| IsThreeState="{TemplateBinding IsThreeState}"> | ||
| <CheckBox.Styles> | ||
| <Style Selector="CheckBox /template/ DockPanel#PART_RootPanel"> | ||
| <Setter Property="HorizontalAlignment" Value="Center" /> | ||
| </Style> | ||
| </CheckBox.Styles> | ||
| </CheckBox> | ||
| </Border> | ||
| </ControlTemplate> | ||
| </Setter> | ||
|
|
||
| <Style Selector="^"> | ||
| <Setter Property="Focusable" Value="False" /> | ||
| <Setter Property="MinWidth" Value="56" /> | ||
| <Setter Property="Padding" Value="8 6" /> | ||
| </Style> | ||
|
|
||
| <Style Selector="^ /template/ CheckBox#PART_CheckBox"> | ||
| <Setter Property="Width" Value="40" /> | ||
| <Setter Property="Padding" Value="0" /> | ||
| </Style> | ||
| </ControlTheme> | ||
| </ResourceDictionary> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.