8 changed files with 293 additions and 234 deletions
@ -0,0 +1,39 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using Avalonia.Data.Core; |
||||
|
using Avalonia.LogicalTree; |
||||
|
|
||||
|
namespace Avalonia.Markup.Parsers.Nodes |
||||
|
{ |
||||
|
internal class ElementNameNode : ExpressionNode |
||||
|
{ |
||||
|
private readonly string _name; |
||||
|
private IDisposable _subscription; |
||||
|
|
||||
|
public ElementNameNode(string name) |
||||
|
{ |
||||
|
_name = name; |
||||
|
} |
||||
|
|
||||
|
public override string Description => $"#{_name}"; |
||||
|
|
||||
|
protected override void StartListeningCore(WeakReference reference) |
||||
|
{ |
||||
|
if (reference.Target is ILogical logical) |
||||
|
{ |
||||
|
_subscription = ControlLocator.Track(logical, _name).Subscribe(ValueChanged); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
_subscription = null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected override void StopListeningCore() |
||||
|
{ |
||||
|
_subscription?.Dispose(); |
||||
|
_subscription = null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,54 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using Avalonia.Data.Core; |
||||
|
using Avalonia.LogicalTree; |
||||
|
|
||||
|
namespace Avalonia.Markup.Parsers.Nodes |
||||
|
{ |
||||
|
internal class FindAncestorNode : ExpressionNode |
||||
|
{ |
||||
|
private readonly int _level; |
||||
|
private readonly Type _ancestorType; |
||||
|
private IDisposable _subscription; |
||||
|
|
||||
|
public FindAncestorNode(Type ancestorType, int level) |
||||
|
{ |
||||
|
_level = level; |
||||
|
_ancestorType = ancestorType; |
||||
|
} |
||||
|
|
||||
|
public override string Description |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
if (_ancestorType == null) |
||||
|
{ |
||||
|
return $"$parent[{_level}]"; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
return $"$parent[{_ancestorType.Name}, {_level}]"; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected override void StartListeningCore(WeakReference reference) |
||||
|
{ |
||||
|
if (reference.Target is ILogical logical) |
||||
|
{ |
||||
|
_subscription = ControlLocator.Track(logical, _level, _ancestorType).Subscribe(ValueChanged); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
_subscription = null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected override void StopListeningCore() |
||||
|
{ |
||||
|
_subscription?.Dispose(); |
||||
|
_subscription = null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using Avalonia.Data.Core; |
||||
|
|
||||
|
namespace Avalonia.Markup.Parsers.Nodes |
||||
|
{ |
||||
|
internal class SelfNode : ExpressionNode |
||||
|
{ |
||||
|
public override string Description => "$self"; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue