Improve Compiled Bindings + Context#999
Merged
wieslawsoltes merged 5 commits intomasterfrom Jan 22, 2026
Merged
Conversation
This was referenced Feb 2, 2026
This was referenced Feb 9, 2026
This was referenced Feb 18, 2026
This was referenced Feb 23, 2026
Closed
This was referenced Mar 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary: Issue 973 – Compiled Bindings + Context
Overview
This PR addresses the compiled binding errors reported in issue 973 by documenting the correct binding pattern and updating the ItemsSource sample to be compiled-binding-safe. It also adds
[DataType]metadata to template-like classes (DocumentTemplate,Document,Tool) to align with Avalonia’sDataTemplateconventions for better design-time inference.Changes Included
Documentation
dock-itemssource.mdwith a working pattern that rebases bindings onto the model via a nestedDataContext.dock-content-guide.mdfor compiled binding errors involvingContext.*, explaining the cause and the recommended fix pattern.Sample Update
samples/DockXamlSample/ItemsSourceExample.axamlto:x:DataType="dock:Document"on the template root.x:DataType="local:MyDocumentModel"to a nested child underDataContext="{Binding Context}".Content,EditableContent,Status) under the nested model-typed subtree.Metadata Improvements
Added
[DataType]attributes to the following properties to enable Avalonia’sx:DataTypeinference and compiled binding metadata mapping:Dock.Model.Avalonia.Controls.DocumentTemplate.DataTypeDock.Model.Avalonia.Controls.Document.DataTypeDock.Model.Avalonia.Controls.Tool.DataTypeWhy This Works
DocumentTemplateusesDocumentas its data context.Document.Contextis typedobject?, so compiled bindings can’t resolveContext.SomePropertydirectly. The nestedDataContext="{Binding Context}"pattern provides a strongly-typed subtree for compiled bindings. Adding[DataType]to template-like types aligns with Avalonia’s conventions and improves design-time and compile-time metadata resolution.Usage Guidance
When using
ItemsSource+DocumentTemplatewith compiled bindings:This avoids compile-time errors like:
Files Touched
docfx/articles/dock-itemssource.mddocfx/articles/dock-content-guide.mdsamples/DockXamlSample/ItemsSourceExample.axamlsrc/Dock.Model.Avalonia/Controls/DocumentTemplate.cssrc/Dock.Model.Avalonia/Controls/Document.cssrc/Dock.Model.Avalonia/Controls/Tool.csNotes
These changes do not alter runtime behavior of
Contextbinding; they document and formalize the correct compiled-binding pattern and improve metadata for tooling and compile-time validation.Fixes #973