From ecfe57246522ae30c25ea80ed449416ab09b984f Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 13 Aug 2016 16:00:18 +0200 Subject: [PATCH] FIx failing test. Introduced in a refactoring a few commits ago where I saw code that looked wrong. It wasn't wrong, it's just the mechanism is a little unintuitive. Added a comment explaining the reasoning. --- src/Markup/Avalonia.Markup.Xaml/Data/Binding.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Markup/Avalonia.Markup.Xaml/Data/Binding.cs b/src/Markup/Avalonia.Markup.Xaml/Data/Binding.cs index 56882ddcbe..87b4772d0a 100644 --- a/src/Markup/Avalonia.Markup.Xaml/Data/Binding.cs +++ b/src/Markup/Avalonia.Markup.Xaml/Data/Binding.cs @@ -274,7 +274,13 @@ namespace Avalonia.Markup.Xaml.Data private IObservable GetParentDataContext(IAvaloniaObject target) { - return target.GetObservable(Control.ParentProperty) + // The DataContext is based on the visual parent and not the logical parent: this may + // seem unintuitive considering the fact that property inheritance works on the logical + // tree, but consider a ContentControl with a ContentPresenter. The ContentControl's + // Content property is bound to a value which becomes the ContentPresenter's + // DataContext - it is from this that the child hosted by the ContentPresenter needs to + // inherit its DataContext. + return target.GetObservable(Visual.VisualParentProperty) .Select(x => { return (x as IAvaloniaObject)?.GetObservable(Control.DataContextProperty) ??