Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docfx/articles/dock-content-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,25 @@ var document = new Document
</DocumentTemplate>
```

### 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
<DocumentTemplate>
<StackPanel x:DataType="Document">
<StackPanel DataContext="{Binding Context}"
x:DataType="vm:MyDocumentModel">
<TextBox Text="{Binding Content}"/>
</StackPanel>
</StackPanel>
</DocumentTemplate>
```

### Issue: Empty/Blank Document Tabs with DataTemplates

**Problem**: Document tabs show up but content is empty when using ViewModel approach.
Expand Down
13 changes: 13 additions & 0 deletions docfx/articles/dock-itemssource.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ public class DocumentModel
</DocumentTemplate>
```

> **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
> <DocumentTemplate>
> <StackPanel x:DataType="Document">
> <StackPanel DataContext="{Binding Context}"
> x:DataType="models:FileDocument">
> <TextBox Text="{Binding Content}"/>
> </StackPanel>
> </StackPanel>
> </DocumentTemplate>
> ```

## Common Use Cases

### File Editor
Expand Down
14 changes: 11 additions & 3 deletions samples/DockXamlSample/ItemsSourceExample.axaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dock="using:Dock.Model.Avalonia.Controls"
xmlns:local="using:DockXamlSample"
x:Class="DockXamlSample.ItemsSourceExample">

Expand Down Expand Up @@ -38,8 +39,15 @@
<StackPanel Margin="10" x:DataType="Document">
<TextBlock Text="Document Title:" FontWeight="Bold"/>
<TextBox Text="{Binding Title}" Margin="0,0,0,10"/>
<TextBlock Text="Context Data:" FontWeight="Bold"/>
<TextBlock Text="{Binding Context}" TextWrapping="Wrap" Height="100" Background="LightGray" Padding="5"/>
<TextBlock Text="Model Content:" FontWeight="Bold"/>
<StackPanel DataContext="{Binding Context}">
<StackPanel x:DataType="local:MyDocumentModel">
<TextBlock Text="{Binding Content}" TextWrapping="Wrap" Height="80" Background="LightGray" Padding="5"/>
<TextBlock Text="Editable Content:" FontWeight="Bold" Margin="0,10,0,0"/>
<TextBox Text="{Binding EditableContent}" AcceptsReturn="True" Height="80"/>
<TextBlock Text="{Binding Status}" Opacity="0.7" Margin="0,8,0,0"/>
</StackPanel>
</StackPanel>
</StackPanel>
</DocumentTemplate>
</DocumentDock.DocumentTemplate>
Expand All @@ -52,4 +60,4 @@

</Grid>

</UserControl>
</UserControl>
1 change: 1 addition & 0 deletions src/Dock.Model.Avalonia/Controls/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public int MdiZIndex
/// <summary>
///
/// </summary>
[DataType]
[IgnoreDataMember]
[JsonIgnore]
public Type? DataType { get; set; }
Expand Down
1 change: 1 addition & 0 deletions src/Dock.Model.Avalonia/Controls/DocumentTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public DocumentTemplate()
/// <summary>
///
/// </summary>
[DataType]
[IgnoreDataMember]
[JsonIgnore]
public Type? DataType { get; set; }
Expand Down
1 change: 1 addition & 0 deletions src/Dock.Model.Avalonia/Controls/Tool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public int MdiZIndex
/// <summary>
///
/// </summary>
[DataType]
[IgnoreDataMember]
[JsonIgnore]
public Type? DataType { get; set; }
Expand Down