4 changed files with 65 additions and 0 deletions
@ -0,0 +1,19 @@ |
|||
<UserControl xmlns="https://github.com/avaloniaui"> |
|||
<StackPanel Orientation="Vertical" Gap="4"> |
|||
<TextBlock Classes="h1">TreeView</TextBlock> |
|||
<TextBlock Classes="h2">Displays a hierachical tree of data.</TextBlock> |
|||
|
|||
<StackPanel Orientation="Horizontal" |
|||
Margin="0,16,0,0" |
|||
HorizontalAlignment="Center" |
|||
Gap="16"> |
|||
<TreeView Items="{Binding}" Width="250" Height="350"> |
|||
<TreeView.ItemTemplate> |
|||
<TreeDataTemplate ItemsSource="{Binding Children}"> |
|||
<TextBlock Text="{Binding Header}"/> |
|||
</TreeDataTemplate> |
|||
</TreeView.ItemTemplate> |
|||
</TreeView> |
|||
</StackPanel> |
|||
</StackPanel> |
|||
</UserControl> |
|||
@ -0,0 +1,37 @@ |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Markup.Xaml; |
|||
|
|||
namespace ControlCatalog.Pages |
|||
{ |
|||
public class TreeViewPage : UserControl |
|||
{ |
|||
public TreeViewPage() |
|||
{ |
|||
this.InitializeComponent(); |
|||
DataContext = CreateNodes(0); |
|||
} |
|||
|
|||
private void InitializeComponent() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
} |
|||
|
|||
private IList<Node> CreateNodes(int level) |
|||
{ |
|||
return Enumerable.Range(0, 10).Select(x => new Node |
|||
{ |
|||
Header = $"Item {x}", |
|||
Children = level < 5 ? CreateNodes(level + 1) : null, |
|||
}).ToList(); |
|||
} |
|||
|
|||
private class Node |
|||
{ |
|||
public string Header { get; set; } |
|||
public IList<Node> Children { get; set; } |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue