Browse Source

clean up

pull/5052/head
Andrey Kunchev 6 years ago
parent
commit
bc39305fd0
  1. 23
      src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathParser.cs
  2. 8
      src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransformSyntheticCompiledBindingMembers.cs

23
src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlBindingPathParser.cs

@ -72,16 +72,16 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
v.Property is AvaloniaSyntheticCompiledBindingProperty prop v.Property is AvaloniaSyntheticCompiledBindingProperty prop
&& prop.Name == SyntheticCompiledBindingPropertyName.ElementName); && prop.Name == SyntheticCompiledBindingPropertyName.ElementName);
var sourceProperty = syntheticCompiledBindingProperties
.FirstOrDefault(v =>
v.Property is AvaloniaSyntheticCompiledBindingProperty prop
&& prop.Name == SyntheticCompiledBindingPropertyName.Source);
var relativeSourceProperty = syntheticCompiledBindingProperties var relativeSourceProperty = syntheticCompiledBindingProperties
.FirstOrDefault(v => .FirstOrDefault(v =>
v.Property is AvaloniaSyntheticCompiledBindingProperty prop v.Property is AvaloniaSyntheticCompiledBindingProperty prop
&& prop.Name == SyntheticCompiledBindingPropertyName.RelativeSource); && prop.Name == SyntheticCompiledBindingPropertyName.RelativeSource);
var sourceProperty = binding.Children.OfType<XamlAstXamlPropertyValueNode>()
.FirstOrDefault(v =>
v.Property is XamlAstClrProperty prop
&& prop.Name == "Source");
if (elementNameProperty?.Values[0] is XamlAstTextNode elementName) if (elementNameProperty?.Values[0] is XamlAstTextNode elementName)
{ {
convertedNode = new BindingExpressionGrammar.NameNode { Name = elementName.Text }; convertedNode = new BindingExpressionGrammar.NameNode { Name = elementName.Text };
@ -91,14 +91,9 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
throw new XamlParseException($"Invalid ElementName '{elementNameProperty.Values[0]}'.", elementNameProperty.Values[0]); throw new XamlParseException($"Invalid ElementName '{elementNameProperty.Values[0]}'.", elementNameProperty.Values[0]);
} }
if (sourceProperty?.Values[0] != null) if (sourceProperty != null && convertedNode != null)
{ {
if (convertedNode != null) throw new XamlParseException("Only one of ElementName, Source, or RelativeSource specified as a binding source. Only one property is allowed.", binding);
{
throw new XamlParseException("Only one of ElementName, Source, or RelativeSource specified as a binding source. Only one property is allowed.", binding);
}
convertedNode = new RawSourceBindingExpressionNode(sourceProperty?.Values[0]);
} }
if (GetRelativeSourceObjectFromAssignment( if (GetRelativeSourceObjectFromAssignment(
@ -223,10 +218,6 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
{ {
binding.Children.Remove(elementNameProperty); binding.Children.Remove(elementNameProperty);
} }
if (sourceProperty != null)
{
binding.Children.Remove(sourceProperty);
}
if (relativeSourceProperty != null) if (relativeSourceProperty != null)
{ {
binding.Children.Remove(relativeSourceProperty); binding.Children.Remove(relativeSourceProperty);

8
src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransformSyntheticCompiledBindingMembers.cs

@ -25,11 +25,6 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
return new AvaloniaSyntheticCompiledBindingProperty(node, return new AvaloniaSyntheticCompiledBindingProperty(node,
SyntheticCompiledBindingPropertyName.RelativeSource); SyntheticCompiledBindingPropertyName.RelativeSource);
} }
else if (prop.Name == "Source")
{
//return new AvaloniaSyntheticCompiledBindingProperty(node,
// SyntheticCompiledBindingPropertyName.Source);
}
} }
return node; return node;
@ -39,8 +34,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
enum SyntheticCompiledBindingPropertyName enum SyntheticCompiledBindingPropertyName
{ {
ElementName, ElementName,
RelativeSource, RelativeSource
Source
} }
class AvaloniaSyntheticCompiledBindingProperty : XamlAstNode, IXamlAstPropertyReference class AvaloniaSyntheticCompiledBindingProperty : XamlAstNode, IXamlAstPropertyReference

Loading…
Cancel
Save