uno-toolkit-ancestor-binding

Bind to outer DataContexts from DataTemplates using Uno Toolkit markup extensions.

9|1|Updated Dec 10, 2024
One-click install
npx skills add https://github.com/unoplatform/studio --skill uno-toolkit-ancestor-binding
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: uno-toolkit-ancestor-binding
Source: https://github.com/unoplatform/studio/tree/main/plugins/uno-platform-studio/skills/uno-toolkit-ancestor-binding
Command: npx skills add https://github.com/unoplatform/studio --skill uno-toolkit-ancestor-binding

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Bind outside a DataTemplate to the outer DataContext using Uno Toolkit's AncestorBinding and ItemsControlBinding.

Core Features & Use Cases

  • AncestorBinding provides access to the ancestor DataContext within a DataTemplate.
  • ItemsControlBinding exposes the parent ItemsControl's DataContext from within item templates.
  • Supports binding to a page ViewModel or other ancestor contexts to keep templates decoupled from the inner DataContext.

Quick Start

Create a DataTemplate that uses AncestorBinding to bind to the outer ViewModel, or use ItemsControlBinding to reach the parent ItemsControl's DataContext.

Frequently Asked Questions about uno-toolkit-ancestor-binding

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I bind to an outer DataContext from inside a DataTemplate in Uno Platform?

To bind to an outer DataContext from inside a DataTemplate, use the Uno Toolkit's AncestorBinding or ItemsControlBinding markup extensions. These extensions resolve the page ViewModel or ancestor ItemsControl's DataContext at runtime.

What is AncestorBinding used for in XAML DataTemplates?

AncestorBinding in XAML DataTemplates provides access to an ancestor's DataContext from within a DataTemplate. It allows inner template elements to bind directly to a page ViewModel or outer context, keeping templates decoupled.

When should I use ItemsControlBinding instead of AncestorBinding?

Use ItemsControlBinding when you need to expose and bind to the parent ItemsControl's DataContext from within its item templates. AncestorBinding targets broader ancestor contexts, while ItemsControlBinding specifically reaches the immediate ItemsControl.

Do I need specific namespace declarations to access ancestor DataContexts in Uno Toolkit?

Yes, resolving the outer DataContext at runtime requires the correct markup extensions and namespace usage in your XAML. You must reference the Uno Toolkit namespace to successfully utilize AncestorBinding or ItemsControlBinding.

Why does my DataTemplate binding fail to reach the page ViewModel in Uno Platform UI code?

DataTemplate binding fails to reach the page ViewModel because the inner DataContext overrides the outer context. Using Uno Toolkit's AncestorBinding or ItemsControlBinding markup extensions resolves this by explicitly targeting the required ancestor DataContext.

Can I keep DataTemplates decoupled from the inner DataContext while accessing page ViewModel properties?

Yes, you can keep DataTemplates decoupled by using AncestorBinding to bind to the outer page ViewModel. This allows templates to access ancestor context properties without relying on the inner DataContext directly.