protected DocumentNode ProvideCurrentTemplate(SceneElement targetElement, PropertyReference targetPropertyReference, out IList <DocumentCompositeNode> auxillaryResources)
        {
            IPlatform platform = this.SceneViewModel.ProjectContext.Platform;
            FrameworkTemplateElement frameworkTemplateElement1 = (FrameworkTemplateElement)null;

            auxillaryResources = (IList <DocumentCompositeNode>)null;
            if (targetElement.IsSet(targetPropertyReference) == PropertyState.Set)
            {
                FrameworkTemplateElement frameworkTemplateElement2 = targetElement.GetLocalValueAsSceneNode(targetPropertyReference) as FrameworkTemplateElement;
                if (frameworkTemplateElement2 != null)
                {
                    frameworkTemplateElement1 = targetElement.ClonePropertyValueAsSceneNode(targetPropertyReference) as FrameworkTemplateElement;
                    if (frameworkTemplateElement1 != null)
                    {
                        auxillaryResources = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindReferencedResources(frameworkTemplateElement2.DocumentNode);
                    }
                }
            }
            if (frameworkTemplateElement1 == null)
            {
                object                computedValue          = targetElement.GetComputedValue(targetPropertyReference);
                DocumentNode          root                   = computedValue == null ? (DocumentNode)null : this.SceneView.GetCorrespondingDocumentNode(platform.ViewObjectFactory.Instantiate(computedValue), true);
                IPropertyId           targetProperty         = (IPropertyId)targetElement.Platform.Metadata.ResolveProperty(BaseFrameworkElement.StyleProperty);
                DocumentCompositeNode documentCompositeNode1 = targetElement.DocumentNode as DocumentCompositeNode;
                if (!targetElement.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf) && documentCompositeNode1 != null && (root == null && targetPropertyReference.ReferenceSteps.Count == 1))
                {
                    ITypeId       styleTargetType = (ITypeId)targetElement.Type;
                    DocumentNode  currentStyle    = (DocumentNode)null;
                    ReferenceStep referenceStep   = targetPropertyReference.ReferenceSteps[0];
                    object        defaultStyleKey = this.GetDefaultStyleKey(targetElement, styleTargetType, targetProperty);
                    if (defaultStyleKey != null)
                    {
                        bool isThemeStyle;
                        IList <DocumentCompositeNode> auxillaryResources1;
                        this.ResolveDefaultStyle(targetElement, defaultStyleKey, true, out currentStyle, out isThemeStyle, out auxillaryResources1);
                    }
                    DocumentCompositeNode documentCompositeNode2 = currentStyle as DocumentCompositeNode;
                    if (documentCompositeNode2 != null)
                    {
                        DocumentCompositeNode documentCompositeNode3 = documentCompositeNode2.Properties[StyleNode.SettersProperty] as DocumentCompositeNode;
                        if (documentCompositeNode3 != null)
                        {
                            foreach (DocumentNode documentNode1 in (IEnumerable <DocumentNode>)documentCompositeNode3.Children)
                            {
                                DocumentCompositeNode documentCompositeNode4 = documentNode1 as DocumentCompositeNode;
                                if (documentCompositeNode4 != null)
                                {
                                    IMemberId    memberId      = (IMemberId)DocumentPrimitiveNode.GetValueAsMember(documentCompositeNode4.Properties[SetterSceneNode.PropertyProperty]);
                                    DocumentNode documentNode2 = documentCompositeNode4.Properties[SetterSceneNode.ValueProperty];
                                    if (memberId != null && documentNode2 != null && referenceStep.Equals((object)memberId))
                                    {
                                        root = documentNode2;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                if (root != null)
                {
                    frameworkTemplateElement1 = this.SceneViewModel.GetSceneNode(root.Clone(this.SceneViewModel.Document.DocumentContext)) as FrameworkTemplateElement;
                    auxillaryResources        = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindReferencedResources(root);
                }
                else
                {
                    frameworkTemplateElement1 = this.SceneViewModel.CreateSceneNode(computedValue) as FrameworkTemplateElement;
                }
            }
            if (frameworkTemplateElement1 == null)
            {
                return((DocumentNode)null);
            }
            return(frameworkTemplateElement1.DocumentNode);
        }
        protected DocumentNode ProvideCurrentStyle(SceneElement targetElement, IType targetType, PropertyReference targetPropertyReference, bool allowDefaultStyle, out IList <DocumentCompositeNode> auxillaryResources)
        {
            auxillaryResources = (IList <DocumentCompositeNode>)null;
            DocumentNode currentStyle = (DocumentNode)null;
            bool         isThemeStyle = false;
            IType        targetType1  = targetType;

            if (!this.TargetProperty.Equals((object)BaseFrameworkElement.StyleProperty))
            {
                IDocumentContext documentContext    = this.SceneViewModel.Document.DocumentContext;
                Type             propertyTargetType = this.SceneViewModel.Document.ProjectContext.MetadataFactory.GetMetadata(this.Type.RuntimeType).GetStylePropertyTargetType((IPropertyId)this.TargetProperty);
                targetType1 = propertyTargetType == (Type)null ? (IType)null : this.SceneViewModel.ProjectContext.GetType(propertyTargetType);
            }
            if (targetElement.IsSet(targetPropertyReference) == PropertyState.Set)
            {
                DocumentNodePath valueAsDocumentNode = targetElement.GetLocalValueAsDocumentNode(targetPropertyReference);
                if (valueAsDocumentNode != null && valueAsDocumentNode.Node is DocumentCompositeNode && PlatformTypes.Style.IsAssignableFrom((ITypeId)valueAsDocumentNode.Node.Type) && (!StyleNode.IsDefaultValue(valueAsDocumentNode.Node) || allowDefaultStyle))
                {
                    StyleNode styleNode = targetElement.ClonePropertyValueAsSceneNode(targetPropertyReference) as StyleNode;
                    if (styleNode != null)
                    {
                        currentStyle       = styleNode.DocumentNode;
                        auxillaryResources = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindReferencedResources(valueAsDocumentNode.Node);
                    }
                }
            }
            if (currentStyle == null)
            {
                object obj = this.ResolveCurrentStyle(targetElement, targetPropertyReference, allowDefaultStyle);
                if (obj != null)
                {
                    DocumentNode correspondingDocumentNode = this.SceneView.GetCorrespondingDocumentNode(this.SceneViewModel.ProjectContext.Platform.ViewObjectFactory.Instantiate(obj), true);
                    if (correspondingDocumentNode != null && PlatformTypes.Style.IsAssignableFrom((ITypeId)correspondingDocumentNode.Type))
                    {
                        currentStyle = correspondingDocumentNode;
                    }
                    else if (obj is Style)
                    {
                        StyleNode styleNode = (StyleNode)this.SceneViewModel.CreateSceneNode(obj);
                        if (targetType1 != null)
                        {
                            styleNode.StyleTargetTypeId = targetType1;
                        }
                        currentStyle = styleNode.DocumentNode;
                    }
                }
                if (currentStyle != null && !allowDefaultStyle && StyleNode.IsDefaultValue(currentStyle))
                {
                    currentStyle = (DocumentNode)null;
                }
            }
            if (currentStyle == null)
            {
                object defaultStyleKey = this.GetDefaultStyleKey(targetElement, (ITypeId)targetType1, (IPropertyId)this.TargetProperty);
                if (defaultStyleKey != null)
                {
                    this.ResolveDefaultStyle(targetElement, defaultStyleKey, allowDefaultStyle, out currentStyle, out isThemeStyle, out auxillaryResources);
                }
            }
            if (currentStyle != null && !allowDefaultStyle)
            {
                List <DocumentCompositeNode> list = new List <DocumentCompositeNode>();
                DocumentCompositeNode        node = currentStyle as DocumentCompositeNode;
                IProperty property = this.SceneViewModel.ProjectContext.ResolveProperty(StyleNode.BasedOnProperty);
                while (node != null && property != null && (node.Type.Equals((object)PlatformTypes.Style) && node.Properties.Count == 2) && (node.Properties[(IPropertyId)property] != null && node.Properties[StyleNode.TargetTypeProperty] != null))
                {
                    node = node.Properties[StyleNode.BasedOnProperty] as DocumentCompositeNode;
                    if (node != null)
                    {
                        if (DocumentNodeUtilities.IsDynamicResource((DocumentNode)node) || DocumentNodeUtilities.IsStaticResource((DocumentNode)node))
                        {
                            DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(node);
                            if (resourceKey != null && auxillaryResources != null)
                            {
                                foreach (DocumentCompositeNode entryNode in (IEnumerable <DocumentCompositeNode>)auxillaryResources)
                                {
                                    if (resourceKey.Equals(ResourceNodeHelper.GetResourceEntryKey(entryNode)))
                                    {
                                        node = entryNode.Properties[DictionaryEntryNode.ValueProperty] as DocumentCompositeNode;
                                        break;
                                    }
                                }
                            }
                        }
                        if (PlatformTypes.Style.IsAssignableFrom((ITypeId)node.Type))
                        {
                            currentStyle = (DocumentNode)node;
                            list.Add(node);
                        }
                    }
                }
                if (auxillaryResources != null)
                {
                    foreach (DocumentNode documentNode in list)
                    {
                        DocumentCompositeNode parent = documentNode.Parent;
                        if (parent != null && parent.Type.Equals((object)PlatformTypes.DictionaryEntry))
                        {
                            auxillaryResources.Remove(parent);
                        }
                    }
                }
                if (currentStyle != null && (list.Count > 0 || currentStyle.DocumentRoot != null))
                {
                    currentStyle = currentStyle.Clone(targetElement.DocumentContext);
                }
                if (auxillaryResources != null)
                {
                    for (int index = 0; index < auxillaryResources.Count; ++index)
                    {
                        if (auxillaryResources[index].DocumentRoot != null)
                        {
                            auxillaryResources[index] = (DocumentCompositeNode)auxillaryResources[index].Clone(targetElement.DocumentContext);
                        }
                    }
                }
                if (isThemeStyle)
                {
                    ReplaceStyleTemplateCommand.StripFormatting(currentStyle);
                    if (auxillaryResources != null)
                    {
                        for (int index = 0; index < auxillaryResources.Count; ++index)
                        {
                            ReplaceStyleTemplateCommand.StripFormatting((DocumentNode)auxillaryResources[index]);
                        }
                    }
                }
                DocumentCompositeNode documentCompositeNode = currentStyle as DocumentCompositeNode;
                if (documentCompositeNode != null && targetType1 != null)
                {
                    documentCompositeNode.Properties[StyleNode.TargetTypeProperty] = (DocumentNode)documentCompositeNode.Context.CreateNode(PlatformTypes.Type, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)targetType1));
                }
                if (targetType1 != null)
                {
                    ReplaceStyleTemplateCommand.ReplaceTemplateTargetType(currentStyle, auxillaryResources, targetType1);
                }
            }
            return(currentStyle);
        }