public void Visit(ElementNode node, INode parentNode)
        {
            if (!Values.TryGetValue(node, out var value) && Context.ExceptionHandler != null)
            {
                return;
            }

            //Set RD to VE
            if (typeof(ResourceDictionary).IsAssignableFrom(Context.Types[node]) && ApplyPropertiesVisitor.TryGetPropertyName(node, parentNode, out XmlName propertyName))
            {
                if ((propertyName.LocalName == "Resources" ||
                     propertyName.LocalName.EndsWith(".Resources", StringComparison.Ordinal)) && value is ResourceDictionary)
                {
                    var source = Values[parentNode];
                    ApplyPropertiesVisitor.SetPropertyValue(source, propertyName, value, Context.RootElement, node, Context, node);
                    return;
                }
            }

            //Only proceed further if the node is a keyless RD
            if (parentNode is IElementNode &&
                Context.Types.TryGetValue((IElementNode)parentNode, out var parentType) &&
                typeof(ResourceDictionary).IsAssignableFrom(parentType) &&
                !((IElementNode)parentNode).Properties.ContainsKey(XmlName.xKey))
            {
                node.Accept(new ApplyPropertiesVisitor(Context, stopOnResourceDictionary: false), parentNode);
            }
            else if (parentNode is ListNode &&
                     typeof(ResourceDictionary).IsAssignableFrom(Context.Types[((IElementNode)parentNode.Parent)]) &&
                     !((IElementNode)parentNode.Parent).Properties.ContainsKey(XmlName.xKey))
            {
                node.Accept(new ApplyPropertiesVisitor(Context, stopOnResourceDictionary: false), parentNode);
            }
        }
        public void Visit(ValueNode node, INode parentNode)
        {
            var parentElement = parentNode as IElementNode;
            var value         = Values [node];
            var source        = Values [parentNode];

            XmlName propertyName;

            if (ApplyPropertiesVisitor.TryGetPropertyName(node, parentNode, out propertyName))
            {
                if (parentElement.SkipProperties.Contains(propertyName))
                {
                    return;
                }
                if (parentElement.SkipPrefix(node.NamespaceResolver.LookupPrefix(propertyName.NamespaceURI)))
                {
                    return;
                }
                if (propertyName.NamespaceURI == "http://schemas.openxmlformats.org/markup-compatibility/2006" &&
                    propertyName.LocalName == "Ignorable")
                {
                    return;
                }
                if (propertyName.LocalName != "MergedWith")
                {
                    return;
                }
                ApplyPropertiesVisitor.SetPropertyValue(source, propertyName, value, Context.RootElement, node, Context, node);
            }
        }
        public void Visit(ElementNode node, INode parentNode)
        {
            var value           = Values[node];
            var parentElement   = parentNode as IElementNode;
            var markupExtension = value as IMarkupExtension;
            var valueProvider   = value as IValueProvider;

            //Set Resources in ResourcesDictionaries
            if (IsCollectionItem(node, parentNode) && parentNode is IElementNode)
            {
                if (typeof(IEnumerable).IsAssignableFrom(Context.Types[parentElement]))
                {
                    var source = Values[parentNode];
                    if (typeof(ResourceDictionary).IsAssignableFrom(Context.Types[parentElement]) && value is Style &&
                        !node.Properties.ContainsKey(XmlName.xKey))
                    {
                        node.Accept(new ApplyPropertiesVisitor(Context), parentNode);
                        if (markupExtension != null)
                        {
                            var serviceProvider = new XamlServiceProvider(node, Context);
                            value = markupExtension.ProvideValue(serviceProvider);
                        }
                        if (valueProvider != null)
                        {
                            var serviceProvider = new XamlServiceProvider(node, Context);
                            value = valueProvider.ProvideValue(serviceProvider);
                        }
                        ((ResourceDictionary)source).Add(value as Style);
                    }
                    else if (typeof(ResourceDictionary).IsAssignableFrom(Context.Types[parentElement]) && !node.Properties.ContainsKey(XmlName.xKey))
                    {
                        throw new XamlParseException("resources in ResourceDictionary require a x:Key attribute", node);
                    }
                    else if (typeof(ResourceDictionary).IsAssignableFrom(Context.Types[parentElement]) && node.Properties.ContainsKey(XmlName.xKey))
                    {
                        node.Accept(new ApplyPropertiesVisitor(Context), parentNode);
                        if (markupExtension != null)
                        {
                            var serviceProvider = new XamlServiceProvider(node, Context);
                            value = markupExtension.ProvideValue(serviceProvider);
                        }
                        if (valueProvider != null)
                        {
                            var serviceProvider = new XamlServiceProvider(node, Context);
                            value = valueProvider.ProvideValue(serviceProvider);
                        }
                        ((ResourceDictionary)source).Add((string)(((ValueNode)node.Properties[XmlName.xKey]).Value), value);
                    }
                }
            }

            //Set RD to VE
            XmlName propertyName;

            if (ApplyPropertiesVisitor.TryGetPropertyName(node, parentNode, out propertyName))
            {
                if ((propertyName.LocalName == "Resources" ||
                     propertyName.LocalName.EndsWith(".Resources", StringComparison.Ordinal)) && value is ResourceDictionary)
                {
                    var source = Values[parentNode];
                    ApplyPropertiesVisitor.SetPropertyValue(source, propertyName, value, Context.RootElement, node, Context, node);
                }
            }
        }