2 using System.Collections.Generic;
3 using Tizen.NUI.Binding;
5 namespace Tizen.NUI.Xaml
7 class RegisterXNamesVisitor : IXamlNodeVisitor
9 public RegisterXNamesVisitor(HydrationContext context)
11 Values = context.Values;
14 Dictionary<INode, object> Values { get; }
16 public TreeVisitingMode VisitingMode => TreeVisitingMode.TopDown;
17 public bool StopOnDataTemplate => true;
18 public bool StopOnResourceDictionary => false;
19 public bool VisitNodeOnDataTemplate => false;
20 public bool SkipChildren(INode node, INode parentNode) => false;
22 public void Visit(ValueNode node, INode parentNode)
24 if (!IsXNameProperty(node, parentNode))
28 ((IElementNode)parentNode).Namescope.RegisterName((string)node.Value, Values[parentNode]);
30 catch (ArgumentException ae)
32 if (ae.ParamName != "name")
34 throw new XamlParseException($"An element with the name \"{(string)node.Value}\" already exists in this NameScope", node);
36 var element = Values[parentNode] as Element;
38 element.StyleId = element.StyleId ?? (string)node.Value;
41 public void Visit(MarkupNode node, INode parentNode)
45 public void Visit(ElementNode node, INode parentNode)
49 public void Visit(RootNode node, INode parentNode)
53 public void Visit(ListNode node, INode parentNode)
57 static bool IsXNameProperty(ValueNode node, INode parentNode)
59 var parentElement = parentNode as IElementNode;
61 if (parentElement != null && parentElement.Properties.TryGetValue(XmlName.xName, out xNameNode) && xNameNode == node)