diff --git a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlType.cs b/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlType.cs index 3cdcc52a62..f8e7529928 100644 --- a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlType.cs +++ b/src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaXamlType.cs @@ -324,15 +324,15 @@ namespace Avalonia.Markup.Xaml.PortableXaml } } - public void ApplyBinding(IAvaloniaObject obj, IBinding binding) + private void ApplyBinding(IAvaloniaObject obj, IBinding binding) { var control = obj as IControl; var property = Property; var xamlBinding = binding as XamlBinding; - //if (control != null && property != Control.DataContextProperty) - // DelayedBinding.Add(control, property, binding); - //else - if (xamlBinding != null) + + if (control != null && property != Control.DataContextProperty) + DelayedBinding.Add(control, property, binding); + else if (xamlBinding != null) obj.Bind(property, xamlBinding.Value, xamlBinding.Anchor?.Target); else obj.Bind(property, binding); diff --git a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/XamlBinding.cs b/src/Markup/Avalonia.Markup.Xaml/PortableXaml/XamlBinding.cs index 580426df73..ba15dfc2b2 100644 --- a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/XamlBinding.cs +++ b/src/Markup/Avalonia.Markup.Xaml/PortableXaml/XamlBinding.cs @@ -5,8 +5,6 @@ using Portable.Xaml; using Portable.Xaml.ComponentModel; using Portable.Xaml.Markup; using System; -using System.Linq; - namespace Avalonia.Markup.Xaml.PortableXaml { @@ -32,25 +30,16 @@ namespace Avalonia.Markup.Xaml.PortableXaml { object anchor = null; - //// The target is not a control, so we need to find an anchor that will let us look - //// up named controls and style resources. First look for the closest IControl in - //// the TopDownValueContext. - - //anchor = context.TopDownValueContext.StoredInstances - // .Select(x => x.Instance) - // .OfType() - // .LastOrDefault(); + // The target is not a control, so we need to find an anchor that will let us look + // up named controls and style resources. First look for the closest IControl in + // the context. anchor = context.GetFirstAmbientValue(); - //// If a control was not found, then try to find the highest-level style as the XAML - //// file could be a XAML file containing only styles. - // anchor = context.TopDownValueContext.StoredInstances - // .Select(x => x.Instance) - // .OfType() - // .FirstOrDefault(); - var rs = context.GetService().RootObject as IStyle; - - return anchor ?? rs ?? context.GetLastOrDefaultAmbientValue(); + // If a control was not found, then try to find the highest-level style as the XAML + // file could be a XAML file containing only styles. + return anchor ?? + context.GetService()?.RootObject as IStyle ?? + context.GetLastOrDefaultAmbientValue(); } private XamlBinding(IBinding binding, object anchor) diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BindingTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BindingTests.cs index 989bd668f4..e63b3996a3 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BindingTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BindingTests.cs @@ -147,26 +147,27 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml } #if OMNIXAML - [Fact(Skip = "OmniXaml doesn't support nested markup extensions. #119")] #else - [Fact] #endif public void Binding_To_Self_Works() { - var xaml = @" - -"; +"; - var window = AvaloniaXamlLoader.Parse(xaml); - var textBlock = (TextBlock)window.Content; + var window = AvaloniaXamlLoader.Parse(xaml); + var textBlock = (TextBlock)window.Content; - textBlock.Tag = "foo"; + textBlock.Tag = "foo"; - Assert.Equal("foo", textBlock.Text); + Assert.Equal("foo", textBlock.Text); + } } [Fact]