-
Notifications
You must be signed in to change notification settings - Fork 803
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?