microsoft / microsoft/microsoft-ui-xaml

Proposal: Tree view node .Tag() method/property

Open
#10,384 0 comments 0 reactions 0 assignees View on GitHub
area-TreeView feature proposal
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

## Summary
Adding a ".Tag()" method/property to the TreeViewNode's. This way we can identify them a different way than just the content.

## Rationale
Consider this: when you’re building a c++ app **without XAML** (while this is "not preferred" by most, my team does this), you end up writing A LOT of messy code just to link data to nodes. Think something like: either write a lot of wrappers for stuff (example concept shown below) or use very unique content for each tree view node (e.g. "1. This is bob's tree view node" "2. This is Angie's tree view node"). Without .Tag(), we’re stuck reinventing the wheel for something every other UI control already does. Why?

Earlier mentioned "Wrappers":
```cpp
struct TSubTreeViewNodeWrapper {
std::wstring tag;
TreeViewNode& node;
};

struct TRootTreeViewNodeWrapper {
std::wstring tag;
TreeViewNode& node;
std::vector children;
};
```

## Scope
| Capability | Priority |
| :---------- | :------- |
| Allow attaching an IInspectable (Object for C#? -- don't know, don't code in it) to a TreeViewNode without extra wrappers | Must |
| Include a TagChanged event to notify when the tag updates | Could |
| Provide basic thread safety for tag access (e.g., std::lock/SRWLock) | Should |

## Important Notes
Example usage:
```cpp
TreeViewNode node;
node.Tag(myCustomData); // Set
IInspectable data = node.Tag(); // Retrieve
```
API proposal:

Add a "Tag" property to the TreeViewNode class. This keeps code clean and avoids hacks like unique content or maintaining separate wrappers.

## Open Questions
None for now.

Contributor guide

Open the contributing guide

Research direction

Start with the TreeViewNode API and review how existing node properties and events are defined. Resolve the proposal's open implementation questions around IInspectable storage, TagChanged, and thread safety; done requires an agreed scope and API design, but the issue names no files or tests to guide implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.