microsoft / microsoft/microsoft-ui-xaml
Binding with ElementName doesn't work from within a TreeViewItem
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
When using a `Binding` with `ElementName` from within a `TreeViewItem` in a `DataTemplate`, the binding is not resolved and no binding errors are reported.
### Steps to reproduce the bug
```xaml
```
```csharp
using Microsoft.UI.Xaml;
using System.Collections.Generic;
namespace App10;
public sealed partial class MainWindow : Window
{
public MainWindow() =>
InitializeComponent();
public List ViewModels { get; } =
[
new("Parent 1")
{
Children=
[
new("Child 1.1"),
new("Child 1.2"),
new("Child 1.3"),
]
},
new("Parent 2")
{
Children=
[
new("Child 2.1"),
new("Child 2.2"),
new("Child 2.3"),
]
},
];
public string Annotation => "Annotation";
}
public class Entity(string name)
{
public string Name { get; } = name;
public List Children { get; set; } = [];
}
```
### Actual behavior

### Expected behavior
`Annotation` property should be accessed and materialized.

### Screenshots
_No response_
### NuGet package version
WinUI 3 - Windows App SDK 1.7.0: 1.7.250310001
### Windows version
Windows 11 (22H2): Build 22621
### Additional context
_No response_
Contributor guide
Research direction
Start by reproducing the sample from MainWindow, focusing on the TreeViewItem, DataTemplate, and ElementName binding. Trace how the binding resolves the window reference, then verify that the Annotation value is displayed without binding errors when the fix is complete.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100