microsoft / microsoft/microsoft-ui-xaml

Proposal: Support Ancestor Binding in WinUI 3 DataTemplates

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

Description

Summary

WinUI 3 should support ancestor binding within DataTemplate by introducing AncestorType or a similar mechanism. This would allow bindings to reference properties of higher-level elements like Page or UserControl directly, simplifying XAML structure and reducing boilerplate code.

Rationale

Improves developer experience by allowing direct binding to parent elements inside DataTemplate, avoiding workarounds.

Aligns with XAML's existing binding patterns in WPF and UWP, making migration to WinUI 3 smoother.

Reduces unnecessary view models and manual property forwarding, making code more maintainable.

Scope

Important Notes

Example Scenario

Currently, there is no direct way to bind to an ancestor element inside a DataTemplate. For instance, if a UserControl contains a ListView, and we want to bind a TextBlock inside the item template to a property on the UserControl, we can't do it directly:





Instead, developers must manually propagate the binding via view models or additional properties on the parent container, adding complexity.

Proposed Solution

Introduce an AncestorType and AncestorLevel binding feature similar to WPF, enabling developers to easily bind to higher-level elements.

Open Questions

Are there technical limitations in WinUI 3 preventing AncestorType support?

Should AncestorType support bindings to non-visual elements like DataContext?

Contributor guide

Open the contributing guide

Research direction

No files, tests, or entry points are named. Begin by investigating how WinUI 3 currently handles bindings inside DataTemplates and compare the proposed AncestorType and AncestorLevel behavior with WPF and UWP; done requires an agreed design that answers the listed technical and non-visual-element questions.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop, frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.