Skip to content

Add parameterless constructor to TreeView component#46

Merged
ThomasRemmery merged 2 commits into10.5.5.Xfrom
copilot/add-treeview-constructor-without-items
Oct 22, 2025
Merged

Add parameterless constructor to TreeView component#46
ThomasRemmery merged 2 commits into10.5.5.Xfrom
copilot/add-treeview-constructor-without-items

Conversation

Copy link
Contributor

Copilot AI commented Oct 22, 2025

Overview

This PR adds a parameterless constructor to the TreeView component class, allowing developers to create a TreeView instance without immediately assigning items to it.

Changes

TreeView.cs

Added a new parameterless constructor that follows the same pattern used by other components in the toolkit (e.g., DropDown):

/// <summary>
/// Initializes a new instance of the <see cref="TreeView" /> class.
/// </summary>
public TreeView() : this(Enumerable.Empty<TreeViewItem>())
{
}

This constructor chains to the existing parameterized constructor with an empty enumerable, ensuring proper initialization of all internal fields.

Usage Example

Before this change, developers had to provide items when creating a TreeView:

var treeView = new TreeView(new[] { item1, item2 });

Now, they can create an empty TreeView and populate it later:

var treeView = new TreeView();
// ... later in the code
treeView.Items = new[] { item1, item2 };

Testing

Added a comprehensive unit test TreeViewParameterlessConstructor() that verifies:

  • TreeView can be instantiated without parameters
  • The Items collection is properly initialized (not null) and empty
  • Items can be assigned after creation
  • All TreeView functionality works correctly with items added post-construction

Security

CodeQL security analysis completed with 0 alerts found. No security vulnerabilities were introduced.

Fixes #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>TreeView constructor without items</issue_title>
<issue_description>Add an extra constructor to the TreeView component class, that allows to create a treeview without immediately assigning items to it.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #45


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: TomW-Skyline <97225679+TomW-Skyline@users.noreply.github.com>
Copilot AI changed the title [WIP] Add constructor to TreeView for no initial items Add parameterless constructor to TreeView component Oct 22, 2025
Copilot AI requested a review from TomW-Skyline October 22, 2025 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TreeView constructor without items

3 participants