diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/XamlIlBindingPathHelper.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/XamlIlBindingPathHelper.cs index 3bea580da0..1974dfe3bc 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/XamlIlBindingPathHelper.cs +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/XamlIlBindingPathHelper.cs @@ -198,24 +198,21 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions case BindingExpressionGrammar.AncestorNode ancestor: if (ancestor.Namespace is null && ancestor.TypeName is null) { - if (ancestor.Namespace is null && ancestor.TypeName is null) + var styledElementType = context.GetAvaloniaTypes().StyledElement; + var ancestorType = context + .ParentNodes() + .OfType() + .Where(x => styledElementType.IsAssignableFrom(x.Type.GetClrType())) + .Skip(1) + .ElementAtOrDefault(ancestor.Level) + ?.Type.GetClrType(); + + if (ancestorType is null) { - var styledElementType = context.GetAvaloniaTypes().StyledElement; - var ancestorType = context - .ParentNodes() - .OfType() - .Where(x => styledElementType.IsAssignableFrom(x.Type.GetClrType())) - .Skip(1) - .ElementAtOrDefault(ancestor.Level) - ?.Type.GetClrType(); - - if (ancestorType is null) - { - throw new XamlX.XamlParseException("Unable to resolve implicit ancestor type based on XAML tree.", lineInfo); - } - - nodes.Add(new FindAncestorPathElementNode(ancestorType, ancestor.Level)); + throw new XamlX.XamlParseException("Unable to resolve implicit ancestor type based on XAML tree.", lineInfo); } + + nodes.Add(new FindAncestorPathElementNode(ancestorType, ancestor.Level)); } else { @@ -622,10 +619,10 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions private readonly IXamlAstValueNode _rawSource; public RawSourcePathElementNode(IXamlAstValueNode rawSource) - :base(rawSource) + : base(rawSource) { _rawSource = rawSource; - + } public IXamlType Type => _rawSource.Type.GetClrType();