-
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 1 commit
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
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> | ||
12 changes: 12 additions & 0 deletions
12
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,12 @@ | ||
| <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/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; | ||
| } | ||
| } |
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.