There is a class on which the tree will be built.

Class Fields: Id , ParentId , Name and so on nonessential fields, that is, the tree data source is List<MyClass> . I want to display a tree in treeView or ultraTree from Infragistics A branch of a tree is an instance of the class indicated above .. well, let Name be displayed

I want to bring this tree, but initially I don’t know the number of nestings. It is necessary to deduce recursively how I do not know.

Next challenge. How to attach a column to this tree, in which I would enter the values ​​I need. And then these values ​​would be stored in a separate class.

Thanks in advance for your understanding and response.

  • how do you want to withdraw it? In Treeview or in the console, browse the tree. What is the source? Add a tree Node code. - Arheus
  • Changed the question. I want to display in Treeview ... A branch is an instance of a class, but let the name be displayed - Goniometr

1 answer 1

Come in order then. xaml:

 <TreeView ItemsSource="{Binding Nodes}"> <TreeView.ItemTemplate> <HierarchicalDataTemplate DataType="{x:Type local:INode}" ItemsSource="{Binding Nodes}"> <TextBlock Margin="2" Text="{Binding Path=Name}" /> </HierarchicalDataTemplate> </TreeView.ItemTemplate> </TreeView> 

DataContext window accordingly:

 public class MainViewModel : ViewModelBase { #region Private Fields private readonly IDataService _dataService; private INode _selectedNode; #endregion Private Fields #region Public Constructors /// <summary> /// Отправная точка, главная ViewModel. /// </summary> public MainViewModel(IDataService dataService) { Contract.Assert(dataService != null); _dataService = dataService; } #endregion Public Constructors #region Public Properties public List<INode> Nodes { get; private set; } public INode SelectedNode { get { return _selectedNode; } set { if (_selectedNode != value) { _selectedNode = value; RaisePropertyChanged(); } } } #endregion Public Properties } 

and INode itself:

  public interface INode { #region Public Properties string Name { get; } List<INode> Nodes { get; } #endregion Public Properties } 

accordingly, it is necessary to add to them a standard binding in the form of a service locator (that would push the context to the window or explicitly do this) and the implementation of the INode interface. Everything else depends on the tasks. Selected node, cascading, etc.