diff --git a/docfx/articles/dock-content-guide.md b/docfx/articles/dock-content-guide.md index 1a6e3f3fa..16bfce481 100644 --- a/docfx/articles/dock-content-guide.md +++ b/docfx/articles/dock-content-guide.md @@ -532,6 +532,25 @@ var document = new Document ``` +### Issue: Compiled binding errors for `Context.*` + +**Problem**: Build errors like "Unable to resolve property or method ... on type 'Document'" when using `{Binding Context.SomeProperty}`. + +**Cause**: `Document.Context` is typed `object?`, so compiled bindings cannot infer model properties from `Context`. + +**Solution**: Rebind a subtree to the model and set `x:DataType`, or cast in the binding path (or disable compiled bindings for that subtree). + +```xaml + + + + + + + +``` + ### Issue: Empty/Blank Document Tabs with DataTemplates **Problem**: Document tabs show up but content is empty when using ViewModel approach. diff --git a/docfx/articles/dock-itemssource.md b/docfx/articles/dock-itemssource.md index ab05128ba..f13e5e6ff 100644 --- a/docfx/articles/dock-itemssource.md +++ b/docfx/articles/dock-itemssource.md @@ -177,6 +177,19 @@ public class DocumentModel ``` +> **Compiled bindings + Context**: When using compiled bindings, `Context` is `object?` on `Document`, so `{Binding Context.SomeProperty}` can fail to compile. Rebind a subtree to the model and set a concrete `x:DataType`, or cast in the binding path: +> +> ```xaml +> +> +> x:DataType="models:FileDocument"> +> +> +> +> +> ``` + ## Common Use Cases ### File Editor diff --git a/samples/DockXamlSample/ItemsSourceExample.axaml b/samples/DockXamlSample/ItemsSourceExample.axaml index 2787f2702..77364c3e5 100644 --- a/samples/DockXamlSample/ItemsSourceExample.axaml +++ b/samples/DockXamlSample/ItemsSourceExample.axaml @@ -1,5 +1,6 @@ @@ -38,8 +39,15 @@ - - + + + + + + + + + @@ -52,4 +60,4 @@ - \ No newline at end of file + diff --git a/src/Dock.Model.Avalonia/Controls/Document.cs b/src/Dock.Model.Avalonia/Controls/Document.cs index 49edc36b1..42a1dcd12 100644 --- a/src/Dock.Model.Avalonia/Controls/Document.cs +++ b/src/Dock.Model.Avalonia/Controls/Document.cs @@ -98,6 +98,7 @@ public int MdiZIndex /// /// /// + [DataType] [IgnoreDataMember] [JsonIgnore] public Type? DataType { get; set; } diff --git a/src/Dock.Model.Avalonia/Controls/DocumentTemplate.cs b/src/Dock.Model.Avalonia/Controls/DocumentTemplate.cs index f3107cf22..c317d5a33 100644 --- a/src/Dock.Model.Avalonia/Controls/DocumentTemplate.cs +++ b/src/Dock.Model.Avalonia/Controls/DocumentTemplate.cs @@ -37,6 +37,7 @@ public DocumentTemplate() /// /// /// + [DataType] [IgnoreDataMember] [JsonIgnore] public Type? DataType { get; set; } diff --git a/src/Dock.Model.Avalonia/Controls/Tool.cs b/src/Dock.Model.Avalonia/Controls/Tool.cs index aea6b76a2..a796681bd 100644 --- a/src/Dock.Model.Avalonia/Controls/Tool.cs +++ b/src/Dock.Model.Avalonia/Controls/Tool.cs @@ -100,6 +100,7 @@ public int MdiZIndex /// /// /// + [DataType] [IgnoreDataMember] [JsonIgnore] public Type? DataType { get; set; }