misc: add binding demo.
This commit is contained in:
parent
5d8297a392
commit
9d17cd0087
@ -4,10 +4,13 @@
|
||||
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="clr-namespace:Semi.Avalonia.Demo.Pages"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
x:CompileBindings="True"
|
||||
x:DataType="vm:TreeViewVm"
|
||||
mc:Ignorable="d">
|
||||
<Panel HorizontalAlignment="Left">
|
||||
<StackPanel HorizontalAlignment="Left">
|
||||
<TreeView>
|
||||
<TreeViewItem Header="Level 1">
|
||||
<TreeViewItem Header="Level 2" />
|
||||
@ -42,5 +45,12 @@
|
||||
</TreeViewItem>
|
||||
</TreeViewItem>
|
||||
</TreeView>
|
||||
</Panel>
|
||||
<TreeView ItemsSource="{Binding Items}">
|
||||
<TreeView.ItemTemplate>
|
||||
<TreeDataTemplate ItemsSource="{Binding Items}">
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
</TreeDataTemplate>
|
||||
</TreeView.ItemTemplate>
|
||||
</TreeView>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
@ -1,6 +1,8 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace Semi.Avalonia.Demo.Pages;
|
||||
|
||||
@ -9,5 +11,34 @@ public partial class TreeViewDemo : UserControl
|
||||
public TreeViewDemo()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.DataContext = new TreeViewVm();
|
||||
}
|
||||
}
|
||||
|
||||
public class TreeViewVm : ObservableObject
|
||||
{
|
||||
public ObservableCollection<TreeViewItemVm> Items { get; set; }
|
||||
|
||||
public TreeViewVm()
|
||||
{
|
||||
Items = new ObservableCollection<TreeViewItemVm>()
|
||||
{
|
||||
new TreeViewItemVm() {Name = "Item 1", Id = "1"},
|
||||
new TreeViewItemVm() {Name = "Item 2", Id = "2"},
|
||||
new TreeViewItemVm() {Name = "Item 3", Id = "3", Items = new ObservableCollection<TreeViewItemVm>()
|
||||
{
|
||||
new TreeViewItemVm() {Name = "Item 3.1", Id = "3.1"},
|
||||
new TreeViewItemVm() {Name = "Item 3.2", Id = "3.2"},
|
||||
new TreeViewItemVm() {Name = "Item 3.3", Id = "3.3"},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public partial class TreeViewItemVm : ObservableObject
|
||||
{
|
||||
public ObservableCollection<TreeViewItemVm> Items { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Id { get; set; }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user