Skip to content

[DevExpress] Add TreeDataGrid #152

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions samples/SampleApp/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<Application.Styles>
<!-- <FluentTheme /> -->
<!-- <StyleInclude Source="avares://Devolutions.AvaloniaTheme.MacOS/MacOSTheme.axaml" /> -->
<!-- <StyleInclude Source="avares://Devolutions.AvaloniaTheme.DevExpress/DevExpressTheme.axaml" /> -->
<StyleInclude Source="avares://Devolutions.AvaloniaTheme.Linux/LinuxTheme.axaml" />
<StyleInclude Source="avares://Devolutions.AvaloniaTheme.DevExpress/DevExpressTheme.axaml" />
<!-- <StyleInclude Source="avares://Devolutions.AvaloniaTheme.Linux/LinuxTheme.axaml" /> -->
<StyleInclude Source="/Styles.axaml" />
</Application.Styles>
</Application>
15 changes: 15 additions & 0 deletions samples/SampleApp/DemoPages/TreeDataGridDemo.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<UserControl xmlns="https://github.com/avaloniaui"
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:vm="using:SampleApp.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SampleApp.DemoPages.TreeDataGridDemo"
x:DataType="vm:TreeDataGridViewModel">

<Design.DataContext>
<vm:TreeDataGridViewModel />
</Design.DataContext>

<TreeDataGrid Source="{Binding Source} " />
</UserControl>
11 changes: 11 additions & 0 deletions samples/SampleApp/DemoPages/TreeDataGridDemo.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Avalonia.Controls;

namespace SampleApp.DemoPages;

public partial class TreeDataGridDemo : UserControl
{
public TreeDataGridDemo()
{
InitializeComponent();
}
}
7 changes: 7 additions & 0 deletions samples/SampleApp/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
<TabItem Header="Toggle Switch [WIP]">
<demoPages:ToggleSwitchDemo />
</TabItem>
<TabItem Header="TreeDataGrid" IsSelected="True">
<demoPages:TreeDataGridDemo>
<demoPages:TreeDataGridDemo.DataContext>
<vm:TreeDataGridViewModel />
</demoPages:TreeDataGridDemo.DataContext>
</demoPages:TreeDataGridDemo>
</TabItem>
<TabItem Header="TreeView">
<demoPages:TreeViewDemo />
</TabItem>
Expand Down
1 change: 1 addition & 0 deletions samples/SampleApp/SampleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.2.8"/>
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.2.8"/>
<PackageReference Include="Avalonia.Controls.TreeDataGrid" Version="11.1.1"/>
<PackageReference Include="Avalonia.Desktop" Version="11.2.8"/>
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.8"/>
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
Expand Down
68 changes: 68 additions & 0 deletions samples/SampleApp/ViewModels/TreeDataGridViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System.Collections.ObjectModel;
using Avalonia.Controls;
using Avalonia.Controls.Models.TreeDataGrid;
using CommunityToolkit.Mvvm.ComponentModel;

namespace SampleApp.ViewModels;

public class Person
{
public string? FirstName { get; set; }
public string? LastName { get; set; }
public int Age { get; set; }
public ObservableCollection<Person> Children { get; } = new();
}

public class TreeDataGridViewModel : ObservableObject
{
private readonly ObservableCollection<Person> _people = new()
{
new Person
{
FirstName = "Eleanor",
LastName = "Pope",
Age = 32,
Children =
{
new Person { FirstName = "Marcel", LastName = "Gutierrez", Age = 4 }
}
},
new Person
{
FirstName = "Jeremy",
LastName = "Navarro",
Age = 74,
Children =
{
new Person
{
FirstName = "Jane",
LastName = "Navarro",
Age = 42,
Children =
{
new Person { FirstName = "Lailah ", LastName = "Velazquez", Age = 16 }
}
}
}
},
new Person { FirstName = "Jazmine", LastName = "Schroeder", Age = 52 }
};

public TreeDataGridViewModel()
{
Source = new HierarchicalTreeDataGridSource<Person>(_people)
{
Columns =
{
new HierarchicalExpanderColumn<Person>(
new TextColumn<Person, string>("First Name", x => x.FirstName),
x => x.Children),
new TextColumn<Person, string>("Last Name", x => x.LastName),
new TextColumn<Person, int>("Age", x => x.Age)
}
};
}

public HierarchicalTreeDataGridSource<Person> Source { get; }
}
9 changes: 9 additions & 0 deletions src/Devolutions.AvaloniaTheme.DevExpress/Accents/Styles.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,13 @@
<Style Selector="DataGridRow:nth-child(even)">
<Setter Property="Background" Value="{DynamicResource DataGridRowAlternatingBackgroundBrush}" />
</Style>

<Style Selector=":is(TreeDataGridCell)">
<Setter Property="Background" Value="Transparent" />
<Setter Property="MinHeight" Value="25" />
</Style>

<Style Selector=":is(TreeDataGridCell):selected">
<Setter Property="Background" Value="{DynamicResource TreeDataGridSelectedCellBackgroundBrush}" />
</Style>
</Styles>
Loading