Zhy.Components.Tree
1.0.3
.NET 5.0
This package targets .NET 5.0. The package is compatible with this framework or higher.
.NET Core 3.0
This package targets .NET Core 3.0. The package is compatible with this framework or higher.
.NET Framework 4.6.1
This package targets .NET Framework 4.6.1. The package is compatible with this framework or higher.
The owner has unlisted this package.
This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Zhy.Components.Tree --version 1.0.3
NuGet\Install-Package Zhy.Components.Tree -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Zhy.Components.Tree" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zhy.Components.Tree" Version="1.0.3" />
<PackageReference Include="Zhy.Components.Tree" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Zhy.Components.Tree --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Zhy.Components.Tree, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Zhy.Components.Tree@1.0.3
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Zhy.Components.Tree&version=1.0.3
#tool nuget:?package=Zhy.Components.Tree&version=1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Zhy.Components.Tree
1 Document
2 Demo - Zhy.Components.Tree
Tree.cs
public class Tree : ObservableObject,IObservableTree<Tree>
{
private string _name;
public string Name
{
get => _name;
set => SetProperty(ref _name, value);
}
//序列化时必须忽略
[JsonIgnore]
public Tree? Parent { get; set; }
private ObservableCollection<Tree>? _children;
public ObservableCollection<Tree>? Children
{
get => _children;
set => SetProperty(ref _children, value);
}
public Tree Clone()
{
Tree clone = new Tree();
clone.Name = Name;
if (Children?.Count > 0)
{
clone.Children = new ObservableCollection<Tree>();
foreach (var child in Children)
{
Tree childClone = child.Clone();
childClone.Parent = clone;
clone.Children.Add(childClone);
}
}
return clone;
}
}
3 Demo - Zhy.Components.Tree.Extension - ObservableTree.Filter

TestTreeNode.cs
using CommunityToolkit.Mvvm.ComponentModel;
using System.Collections.ObjectModel;
namespace Zhy.Components.Tree.Test
{
public partial class TestTreeNode : ObservableObject, IObservableTree<TestTreeNode>
{
public TestTreeNode Parent { get; set; }
[ObservableProperty]
private string _name;
[ObservableProperty]
private ObservableCollection<TestTreeNode> _children;
//public ObservableCollection<TestTreeNode> Children
//{
// get => _children;
// set => SetProperty(ref _children, value);
//}
public TestTreeNode Clone()
{
TestTreeNode clone = new TestTreeNode
{
Name = _name,
};
if (Children?.Count > 0)
{
clone.Children = new ObservableCollection<TestTreeNode>();
foreach (var child in Children)
{
TestTreeNode subClone = child.Clone();
subClone.Parent = this;
clone.Children.Add(subClone);
}
}
return clone;
}
}
}
MainWindow.xaml
<Window
x:Class="Zhy.Components.Tree.Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Zhy.Components.Tree.Test"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MainWindow"
Width="800"
Height="450"
mc:Ignorable="d">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition />
</Grid.RowDefinitions>
<DockPanel>
<Button
Command="{Binding SearchCommand}"
Content="查 询"
Cursor="Hand"
DockPanel.Dock="Right" />
<TextBox Text="{Binding SearchText}" />
</DockPanel>
<TreeView
Grid.Row="1"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
ItemsSource="{Binding TreeNodes}">
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="True" />
</Style>
</TreeView.ItemContainerStyle>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
<DockPanel x:Name="dp" Margin="0,2,0,2">
<TextBlock
VerticalAlignment="Center"
FontSize="14"
IsHitTestVisible="True"
Text="{Binding Name}" />
<TextBlock IsHitTestVisible="True" />
</DockPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Grid>
</Window>
MainWindowViewModel.cs
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Collections.ObjectModel;
using Zhy.Components.Tree.Extension;
namespace Zhy.Components.Tree.Test
{
public partial class MainWindowViewModel : ObservableObject
{
[ObservableProperty]
private ObservableCollection<TestTreeNode> _treeNodes;
[ObservableProperty]
private string _searchText;
public MainWindowViewModel()
{
_treeNodes = new ObservableCollection<TestTreeNode>
{
new TestTreeNode
{
Name = "资源目录",
Children = new ObservableCollection<TestTreeNode>
{
new TestTreeNode
{
Name = "矢量",
Children = new ObservableCollection<TestTreeNode>
{
new TestTreeNode
{
Name = "行政区划",
Children = new ObservableCollection<TestTreeNode>
{
new TestTreeNode
{
Name = "北京行政区划"
},
new TestTreeNode
{
Name = "天津行政区划"
},
new TestTreeNode
{
Name = "河北行政区划"
},
}
},
new TestTreeNode
{
Name = "管线",
}
}
},
new TestTreeNode
{
Name = "栅格",
Children = new ObservableCollection<TestTreeNode>
{
new TestTreeNode
{
Name = "正射影像",
Children = new ObservableCollection<TestTreeNode>
{
new TestTreeNode
{
Name = "北京遥感影像"
},
new TestTreeNode
{
Name = "天津遥感影像"
},
new TestTreeNode
{
Name = "河北遥感影像"
},
}
},
new TestTreeNode
{
Name = "DEM"
}
}
}
}
},
};
}
[RelayCommand]
private void Search()
{
foreach (var item in TreeNodes)
{
item.Filter(n => n.Name.Contains(SearchText));
}
}
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 is compatible. netcoreapp3.1 is compatible. |
| .NET Framework | net461 is compatible. net462 is compatible. net463 was computed. net47 is compatible. net471 is compatible. net472 is compatible. net48 is compatible. net481 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 3.0
- No dependencies.
-
.NETCoreApp 3.1
- No dependencies.
-
.NETFramework 4.6.1
- System.Text.Json (>= 4.6.0)
-
.NETFramework 4.6.2
- System.Text.Json (>= 4.6.0)
-
.NETFramework 4.7
- System.Text.Json (>= 4.7.0)
-
.NETFramework 4.7.1
- System.Text.Json (>= 4.7.1)
-
.NETFramework 4.7.2
- System.Text.Json (>= 4.7.2)
-
.NETFramework 4.8
- System.Text.Json (>= 4.7.2)
-
.NETFramework 4.8.1
- System.Text.Json (>= 4.7.2)
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|
1.优化结构,增加扩展。