TreeListBox only showing root, can i get some more help?

Grids for WPF Forum

Posted 2 months ago by hayan khaddour
Version: 23.1.4
Avatar
<docking:ToolWindow Title="Units Explorer" CanClose="False">
    <grids:TreeListBox BorderThickness="0" IsRootItemVisible="True" TopLevelIndent="2">
        <grids:TreeListBox.ItemAdapter>
            <common:DefaultTreeListBoxItemAdapter TopLevelExpandabilityDefault="Auto" IsExpandedDefault="True" ChildrenQueryModeDefault="OnDisplay"/>
        </grids:TreeListBox.ItemAdapter>

        <grids:TreeListBox.ItemTemplate>
            <DataTemplate >
                <StackPanel Orientation="Horizontal">
                    <TextBlock Margin="4,0,0,0" Text="{Binding Name}" TextTrimming="CharacterEllipsis" VerticalAlignment="Center" />
                </StackPanel>
            </DataTemplate>
        </grids:TreeListBox.ItemTemplate>

        <common:TreeNodeModel Name="Fruits" IsExpanded="True">
            <common:TreeNodeModel Name="Blackberry" />
            <common:TreeNodeModel Name="Blackberry" />
            <common:TreeNodeModel Name="Blueberry" />
            <common:TreeNodeModel Name="Cranberry" />
            <common:TreeNodeModel Name="Grapes" />
            <common:TreeNodeModel Name="Raspberry" />
            <common:TreeNodeModel Name="Strawberry" />
            <common:TreeNodeModel Name="Berries">
                <common:TreeNodeModel Name="Blackberry" />
                <common:TreeNodeModel Name="Blueberry" />
                <common:TreeNodeModel Name="Cranberry" />
                <common:TreeNodeModel Name="Grapes" />
                <common:TreeNodeModel Name="Raspberry" />
                <common:TreeNodeModel Name="Strawberry" />
            </common:TreeNodeModel>
            <common:TreeNodeModel Name="Other" IsExpanded="True">
                <common:TreeNodeModel Name="Apple" />
                <common:TreeNodeModel Name="Banana" />
                <common:TreeNodeModel Name="Cherry" />
                <common:TreeNodeModel Name="Grapefruit" />
                <common:TreeNodeModel Name="Guava" />
                <common:TreeNodeModel Name="Lemon" />
                <common:TreeNodeModel Name="Lime" />
                <common:TreeNodeModel Name="Kiwi" />
                <common:TreeNodeModel Name="Orange" />
                <common:TreeNodeModel Name="Pineapple" />
                <common:TreeNodeModel Name="Plum" />
            </common:TreeNodeModel>
        </common:TreeNodeModel>

    </grids:TreeListBox>
</docking:ToolWindow>

Comments (2)

Posted 2 months ago by hayan khaddour
Avatar
using ActiproSoftware.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;

namespace EmpirBus.Switching.FirmwareManager.App.Feature.Common
{
    [ContentProperty("Children")]    
    public partial class TreeNodeModel : ObservableObject
    {
        public ObservableCollection<TreeNodeModel> Children { get; set; } = new ObservableCollection<TreeNodeModel>();
        [ObservableProperty]
        private ICommand _defaultActionCommand;
        [ObservableProperty]
        private ImageSource _imageSource;
        [ObservableProperty]
        private bool _isDraggable = true;
        [ObservableProperty]
        private bool _isEditable;
        [ObservableProperty]
        private bool _isEditing;
        [ObservableProperty]
        private bool _isExpanded = true;
        [ObservableProperty]
        private bool _isLoading;
        [ObservableProperty]
        private bool _isSelectable = true;
        [ObservableProperty]
        private bool _isSelected;
        [ObservableProperty]
        private string _name;
        [ObservableProperty]
        private object _tag;
        /// <summary>
        /// The Firmware model
        /// </summary>
        [ObservableProperty]
        private object _innerModel;
    }
}
public class DefaultTreeListBoxItemAdapter : TreeListBoxItemAdapter
{

    public SortDescription? SortDescription { get; set; }

    public DefaultTreeListBoxItemAdapter()
    {
        this.ChildrenPath = "Children";
        this.IsEditingPath = "IsEditing";
        this.IsExpandedPath = "IsExpanded";
        this.IsLoadingPath = "IsLoading";
        this.IsSelectablePath = "IsSelectable";
        this.IsSelectedPath = "IsSelected";            
    }


    public override IEnumerable GetChildren(TreeListBox ownerControl, object item)
    {
        var model = item as TreeNodeModel;
        var enumerable = (model != null ? model.Children : null);

        if (this.SortDescription.HasValue)
        {
            var collectionViewSource = new CollectionViewSource()
            {
                SortDescriptions = {
                    this.SortDescription.Value
                },
                Source = enumerable,
            };
            return collectionViewSource.View;
        }

        return base.GetChildren(ownerControl, item);
    }

    public override ICommand GetDefaultActionCommand(TreeListBox ownerControl, object item)
    {
        var model = item as TreeNodeModel;
        return (model != null ? model.DefaultActionCommand : null);
    }

    public override bool GetIsDraggable(TreeListBox ownerControl, object item)
    {
        var model = item as TreeNodeModel;
        return (model != null ? model.IsDraggable : false);
    }

    public override bool GetIsEditable(TreeListBox ownerControl, object item)
    {
        var model = item as TreeNodeModel;
        return (model != null ? model.IsEditable : false);
    }

    public override bool GetIsEditing(TreeListBox ownerControl, object item)
    {
        var model = item as TreeNodeModel;
        return (model != null ? model.IsEditing : false);
    }

    public override bool GetIsExpanded(TreeListBox ownerControl, object item)
    {
        var model = item as TreeNodeModel;
        return (model != null ? model.IsExpanded : false);
    }

    public override bool GetIsLoading(TreeListBox ownerControl, object item)
    {
        var model = item as TreeNodeModel;
        return (model != null ? model.IsLoading : false);
    }

    public override bool GetIsSelectable(TreeListBox ownerControl, object item)
    {
        var model = item as TreeNodeModel;
        return (model != null ? model.IsSelectable : true);
    }

    public override bool GetIsSelected(TreeListBox ownerControl, object item)
    {
        var model = item as TreeNodeModel;
        return (model != null ? model.IsSelected : false);
    }

    public override string GetPath(TreeListBox ownerControl, object item)
    {
        var model = item as TreeNodeModel;
        return (model != null ? model.Name : null);
    }

    public override string GetSearchText(TreeListBox ownerControl, object item)
    {
        var model = item as TreeNodeModel;
        return (model != null ? model.Name : null);
    }

    public override void SetIsEditing(TreeListBox ownerControl, object item, bool value)
    {
        var model = item as TreeNodeModel;
        if (model != null)
            model.IsEditing = value;
    }

    public override void SetIsExpanded(TreeListBox ownerControl, object item, bool value)
    {
        var model = item as TreeNodeModel;
        if (model != null)
            model.IsExpanded = value;
    }

    public override void SetIsSelected(TreeListBox ownerControl, object item, bool value)
    {
        var model = item as TreeNodeModel;
        if (model != null)
            model.IsSelected = value;
    }

}
Answer - Posted 2 months ago by hayan khaddour
Avatar
return base.GetChildren(ownerControl, item);

This was the issue

The latest build of this product (v24.1.2) was released 4 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.