예제 #1
0
        private static void CheckForInvalidBinding(ViewNode viewNode)
        {
            if (viewNode == null || viewNode.DocumentNode == null || viewNode.DocumentNode.Parent == null || !viewNode.DocumentNode.IsProperty)
            {
                return;
            }
            IProperty sitePropertyKey = viewNode.DocumentNode.SitePropertyKey;

            if (KnownProperties.ContentControlContentProperty.Equals(sitePropertyKey) || KnownProperties.ContentPresenterContentProperty.Equals(sitePropertyKey))
            {
                DocumentCompositeNode documentNode = (DocumentCompositeNode)viewNode.DocumentNode;
                if (DocumentNodeUtilities.IsBinding(documentNode))
                {
                    DocumentNode item          = documentNode.Properties[KnownProperties.BindingPathProperty];
                    DocumentNode item1         = documentNode.Properties[KnownProperties.BindingRelativeSourceProperty];
                    DocumentNode documentNode1 = documentNode.Properties[KnownProperties.BindingElementNameProperty];
                    if (item == null && (item1 != null || documentNode1 != null))
                    {
                        CultureInfo currentCulture = CultureInfo.CurrentCulture;
                        string      invalidBindingToVisualTreeElement = ExceptionStringTable.InvalidBindingToVisualTreeElement;
                        object[]    name = new object[] { sitePropertyKey.Name };
                        throw new InvalidOperationException(string.Format(currentCulture, invalidBindingToVisualTreeElement, name));
                    }
                }
            }
        }
예제 #2
0
 protected virtual bool IsValueValidForVerification(DocumentNode valueNode)
 {
     if (!DocumentNodeUtilities.IsBinding(valueNode) && !DocumentNodeUtilities.IsTemplateBinding(valueNode))
     {
         return(!DocumentNodeUtilities.IsStaticExtension(valueNode));
     }
     return(false);
 }
예제 #3
0
        public static DocumentNode FindTargetElement(DocumentNode node, bool resolveTargetName)
        {
            DocumentCompositeNode documentCompositeNode1 = node as DocumentCompositeNode;

            if (documentCompositeNode1 != null)
            {
                DocumentNode documentNode1 = documentCompositeNode1.Properties[BehaviorTargetedTriggerActionNode.BehaviorTargetNameProperty];
                string       elementName   = !resolveTargetName || documentNode1 == null || !DocumentNodeUtilities.IsResource(documentNode1) ? documentCompositeNode1.GetValueAsString(BehaviorTargetedTriggerActionNode.BehaviorTargetNameProperty) : DocumentPrimitiveNode.GetValueAsString(ExpressionEvaluator.EvaluateExpression(documentNode1));
                IProperty    property1     = node.PlatformMetadata.ResolveProperty(BehaviorTargetedTriggerActionNode.BehaviorTargetObjectProperty);
                if (property1 != null)
                {
                    DocumentNode documentNode2 = documentCompositeNode1.Properties[(IPropertyId)property1];
                    if (documentNode2 != null)
                    {
                        if (DocumentNodeUtilities.IsMarkupExtension(documentNode2))
                        {
                            if (!DocumentNodeUtilities.IsBinding(documentNode2) || !GoToStateActionNode.CanResolveTargetFromBinding(documentNode2))
                            {
                                return(ExpressionEvaluator.EvaluateExpression(documentNode2));
                            }
                            documentNode2 = GoToStateActionNode.ResolveTargetFromBinding(node, (DocumentCompositeNode)documentNode2);
                        }
                        return(documentNode2);
                    }
                }
                if (!string.IsNullOrEmpty(elementName))
                {
                    return(BehaviorHelper.FindNamedElement(node, elementName));
                }
                DocumentNode documentNode3;
                for (documentNode3 = (DocumentNode)documentCompositeNode1; documentNode3 != null; documentNode3 = (DocumentNode)documentNode3.Parent)
                {
                    DocumentCompositeNode documentCompositeNode2 = documentNode3 as DocumentCompositeNode;
                    IProperty             property2 = node.TypeResolver.ResolveProperty(VisualStateManagerSceneNode.VisualStateGroupsProperty);
                    if (property2 == null)
                    {
                        return((DocumentNode)null);
                    }
                    if (documentCompositeNode2 != null && documentCompositeNode2.Properties[(IPropertyId)property2] != null)
                    {
                        break;
                    }
                }
                if (documentNode3 != null)
                {
                    DocumentCompositeNode parent = documentNode3.Parent;
                    if (parent != null && PlatformTypes.ICollection.IsAssignableFrom((ITypeId)parent.Type) && parent.Parent != null)
                    {
                        return((DocumentNode)parent.Parent);
                    }
                    return((DocumentNode)documentNode3.Parent);
                }
            }
            return((DocumentNode)null);
        }
예제 #4
0
        public static bool CanResolveTargetFromBinding(DocumentNode node)
        {
            if (node == null || !DocumentNodeUtilities.IsBinding(node))
            {
                return(false);
            }
            DocumentCompositeNode documentCompositeNode = (DocumentCompositeNode)node;

            if (documentCompositeNode.Properties[BindingSceneNode.ElementNameProperty] != null)
            {
                return(documentCompositeNode.Properties[BindingSceneNode.PathProperty] == null);
            }
            return(false);
        }
예제 #5
0
 private bool HasValidValue(SceneViewModel viewModel, DocumentNodePath documentNodePath)
 {
     if (documentNodePath != null && !DocumentNodeUtilities.IsBinding(documentNodePath.Node))
     {
         SceneView activeView = viewModel.DesignerContext.ActiveView;
         if (activeView != null)
         {
             IInstanceBuilderContext instanceBuilderContext = activeView.InstanceBuilderContext;
             IExceptionDictionary    exceptionDictionary    = instanceBuilderContext.ExceptionDictionary;
             ViewNode viewNode;
             if (instanceBuilderContext.ViewNodeManager.TryGetCorrespondingViewNode(documentNodePath, out viewNode))
             {
                 return(!exceptionDictionary.Contains(viewNode));
             }
             return(true);
         }
     }
     return(false);
 }
예제 #6
0
        public List <ViewNode> GetExpressionValue(DocumentNode target)
        {
            List <ViewNode> viewNodes;
            List <ViewNode> viewNodes1 = new List <ViewNode>();
            List <ViewNode> viewNodes2 = null;

            if (base.TryGetValue(target, out viewNodes))
            {
                foreach (ViewNode viewNode in viewNodes)
                {
                    if (viewNode.Parent != null)
                    {
                        if (DocumentNodeUtilities.IsBinding(target))
                        {
                            continue;
                        }
                        viewNodes1.Add(viewNode);
                    }
                    else
                    {
                        if (viewNodes2 == null)
                        {
                            viewNodes2 = new List <ViewNode>();
                        }
                        viewNodes2.Add(viewNode);
                    }
                }
                if (viewNodes2 != null)
                {
                    if (viewNodes2.Count != viewNodes.Count)
                    {
                        this.PurgePartialEntry(viewNodes, viewNodes2);
                    }
                    else
                    {
                        base.Remove(target);
                    }
                }
            }
            return(viewNodes1);
        }
예제 #7
0
        public override bool Verify(DocumentNode node)
        {
            DocumentCompositeNode compositeNode = node as DocumentCompositeNode;

            if (this.builder == null)
            {
                this.builder = new StateNameBuilder(this.designerContext);
                this.builder.Begin();
            }
            if (compositeNode != null)
            {
                string        referentialPropertyValue = this.GetReferentialPropertyValue(compositeNode);
                DocumentNode  targetElement            = GoToStateActionNode.FindTargetElement(node, true);
                List <string> results;
                if (targetElement != null && (DocumentNodeUtilities.IsBinding(targetElement) && !GoToStateActionNode.CanResolveTargetFromBinding(targetElement) || Enumerable.Contains <string>(this.builder.GetStateNamesForNode(targetElement), referentialPropertyValue) || PlatformNeutralAttributeHelper.TryGetAttributeValues <string>((IEnumerable)TypeUtilities.GetAttributes(targetElement.TargetType), ProjectNeutralTypes.TemplateVisualStateAttribute, "Name", out results) && results.Contains(referentialPropertyValue)))
                {
                    return(true);
                }
            }
            return(false);
        }
        public override bool Verify(DocumentNode node)
        {
            DocumentCompositeNode compositeNode = node as DocumentCompositeNode;

            if (compositeNode != null)
            {
                if (DocumentNodeUtilities.IsBinding(node))
                {
                    return(true);
                }
                string referentialPropertyValue = this.GetReferentialPropertyValue(compositeNode);
                if (string.IsNullOrEmpty(referentialPropertyValue))
                {
                    return(this.allowNullOrEmpty);
                }
                IPrototypingService prototypingService = this.designerContext.PrototypingService;
                if (prototypingService != null && prototypingService.ScreenExists(referentialPropertyValue))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #9
0
        public List <ViewNode> Validate(IInstanceBuilderContext context, out List <ExpressionSite> sites)
        {
            ExpressionSite      expressionSite;
            bool                flag;
            DocumentNode        item;
            DocumentNode        documentNode;
            DocumentNode        item1;
            List <DocumentNode> documentNodes = new List <DocumentNode>();
            List <ViewNode>     viewNodes     = new List <ViewNode>();
            List <ViewNode>     viewNodes1    = new List <ViewNode>();

            sites = new List <ExpressionSite>();
            ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator(context.DocumentRootResolver);

            foreach (KeyValuePair <DocumentNode, List <ViewNode> > keyValuePair in this)
            {
                DocumentNode key = keyValuePair.Key;
                viewNodes1.Clear();
                foreach (ViewNode value in keyValuePair.Value)
                {
                    ViewNode parent = value.Parent;
                    if (parent != null)
                    {
                        DocumentNode documentNode1 = parent.DocumentNode;
                        if (!value.IsProperty)
                        {
                            int num = value.Parent.Children.IndexOf(value);
                            expressionSite = new ExpressionSite(num);
                        }
                        else
                        {
                            expressionSite = new ExpressionSite(value.SitePropertyKey);
                        }
                        bool flag1 = ExpressionCache.HasInvalidAncestor(context, parent, out flag);
                        if (!flag)
                        {
                            continue;
                        }
                        if (!flag1)
                        {
                            DocumentNodePath      correspondingNodePath = context.ViewNodeManager.GetCorrespondingNodePath(parent);
                            DocumentCompositeNode node = (DocumentCompositeNode)correspondingNodePath.Node;
                            if (expressionSite.IsProperty)
                            {
                                item = node.Properties[expressionSite.PropertyKey];
                            }
                            else if (node.Children == null)
                            {
                                if (expressionSite.ChildIndex < node.ConstructorArguments.Count)
                                {
                                    documentNode = node.ConstructorArguments[expressionSite.ChildIndex];
                                }
                                else
                                {
                                    documentNode = null;
                                }
                                item = documentNode;
                            }
                            else
                            {
                                if (expressionSite.ChildIndex < node.Children.Count)
                                {
                                    item1 = node.Children[expressionSite.ChildIndex];
                                }
                                else
                                {
                                    item1 = null;
                                }
                                item = item1;
                            }
                            DocumentNode documentNode2 = value.DocumentNode;
                            bool         flag2         = true;
                            if (item != null)
                            {
                                if (!DocumentNodeUtilities.IsBinding(value.DocumentNode))
                                {
                                    flag2         = false;
                                    documentNode2 = expressionEvaluator.EvaluateExpression(correspondingNodePath, item);
                                }
                                else
                                {
                                    IPropertyId propertyId = value.DocumentNode.TypeResolver.ResolveProperty(Microsoft.Expression.DesignModel.Metadata.KnownProperties.BindingElementNameProperty);
                                    if (propertyId != null)
                                    {
                                        DocumentNode item2 = ((DocumentCompositeNode)value.DocumentNode).Properties[propertyId];
                                        if (item2 != null)
                                        {
                                            DocumentPrimitiveNode documentPrimitiveNode = item2 as DocumentPrimitiveNode;
                                            if (documentPrimitiveNode != null)
                                            {
                                                DocumentNodeStringValue documentNodeStringValue = documentPrimitiveNode.Value as DocumentNodeStringValue;
                                                if (documentNodeStringValue != null)
                                                {
                                                    string str = documentNodeStringValue.Value;
                                                    object obj = context.NameScope.FindName(str);
                                                    if (obj != null)
                                                    {
                                                        ViewNode      viewNode = context.InstanceDictionary.GetViewNode(obj, false);
                                                        InstanceState invalid  = InstanceState.Invalid;
                                                        if (viewNode != null && !ExpressionCache.HasInvalidAncestor(context, viewNode, out flag))
                                                        {
                                                            invalid = viewNode.InstanceState;
                                                        }
                                                        if (invalid != InstanceState.Invalid && (invalid.InvalidProperties == null || !invalid.InvalidProperties.Contains(viewNode.DocumentNode.NameProperty)))
                                                        {
                                                            documentNode2 = viewNode.DocumentNode;
                                                            flag2         = false;
                                                        }
                                                        else if (parent.Instance is VisualBrush && expressionSite.IsProperty && Microsoft.Expression.DesignModel.Metadata.KnownProperties.VisualBrushVisualProperty.Equals(expressionSite.PropertyKey))
                                                        {
                                                            BindingOperations.ClearBinding((VisualBrush)parent.Instance, VisualBrush.VisualProperty);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (key != item == (documentNode2 != null) && (documentNode2 == null || documentNode2 == key) && !flag2)
                            {
                                continue;
                            }
                            viewNodes1.Add(value);
                            viewNodes.Add(parent);
                            sites.Add(expressionSite);
                        }
                        else
                        {
                            viewNodes1.Add(value);
                        }
                    }
                    else
                    {
                        viewNodes1.Add(value);
                    }
                }
                if (viewNodes1.Count != keyValuePair.Value.Count)
                {
                    this.PurgePartialEntry(keyValuePair.Value, viewNodes1);
                }
                else
                {
                    documentNodes.Add(keyValuePair.Key);
                }
            }
            foreach (DocumentNode documentNode3 in documentNodes)
            {
                base.Remove(documentNode3);
            }
            return(viewNodes);
        }
        public override void UpdateProperty(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode)
        {
            string        instance;
            string        str;
            IPropertyId   shadowProperty;
            ReferenceStep referenceStep = propertyKey as ReferenceStep;
            ViewNode      item          = viewNode.Properties[propertyKey];

            if (item != null && DocumentNodeUtilities.IsBinding(item.DocumentNode) && referenceStep != null)
            {
                ReferenceStep referenceStep1 = referenceStep;
                if (context.UseShadowProperties)
                {
                    shadowProperty = DesignTimeProperties.GetShadowProperty(propertyKey, viewNode.DocumentNode.Type);
                }
                else
                {
                    shadowProperty = null;
                }
                IPropertyId propertyId = shadowProperty;
                if (propertyId != null && DesignTimeProperties.UseShadowPropertyForInstanceBuilding(context.DocumentContext.TypeResolver, propertyId))
                {
                    referenceStep1 = propertyId as ReferenceStep;
                }
                if (referenceStep1 != null)
                {
                    IInstantiatedElementViewNode instantiatedElementViewNode = viewNode as IInstantiatedElementViewNode;
                    if (instantiatedElementViewNode == null)
                    {
                        referenceStep1.ClearValue(viewNode.Instance);
                    }
                    else
                    {
                        foreach (object instantiatedElement in instantiatedElementViewNode.InstantiatedElements)
                        {
                            referenceStep1.ClearValue(instantiatedElement);
                        }
                    }
                }
            }
            if (propertyKey.DeclaringType.Metadata.IsNameProperty(propertyKey) && InstanceBuilderOperations.GetIsInlinedResourceWithoutNamescope(viewNode))
            {
                InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, propertyKey, valueNode);
                return;
            }
            INameScope nameScope = context.NameScope;
            bool       flag      = (nameScope == null ? false : propertyKey.DeclaringType.Metadata.IsNameProperty(propertyKey));

            if (flag)
            {
                ViewNode item1 = viewNode.Properties[propertyKey];
                if (item1 != null)
                {
                    str = item1.Instance as string;
                }
                else
                {
                    str = null;
                }
                string str1 = str;
                if (!string.IsNullOrEmpty(str1) && nameScope.FindName(str1) != null)
                {
                    context.NameScope.UnregisterName(str1);
                }
            }
            if ((!context.IsSerializationScope || !(propertyKey is Event)) && (context.IsSerializationScope || !DesignTimeProperties.IsDocumentOnlyDesignTimeProperty(propertyKey)))
            {
                base.UpdateProperty(context, viewNode, propertyKey, valueNode);
            }
            else
            {
                InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, propertyKey, valueNode);
            }
            if (flag)
            {
                ViewNode viewNode1 = viewNode.Properties[propertyKey];
                if (viewNode1 != null)
                {
                    instance = viewNode1.Instance as string;
                }
                else
                {
                    instance = null;
                }
                string str2 = instance;
                if (!string.IsNullOrEmpty(str2))
                {
                    try
                    {
                        if (!str2.StartsWith("~", StringComparison.Ordinal) && !str2.Contains("."))
                        {
                            if (nameScope.FindName(str2) != null)
                            {
                                nameScope.UnregisterName(str2);
                            }
                            nameScope.RegisterName(str2, viewNode.Instance);
                        }
                    }
                    catch (ArgumentException argumentException1)
                    {
                        ArgumentException argumentException = argumentException1;
                        ViewNodeManager   viewNodeManager   = viewNode1.ViewNodeManager;
                        CultureInfo       currentCulture    = CultureInfo.CurrentCulture;
                        string            instanceBuilderUnableToRegisterName = ExceptionStringTable.InstanceBuilderUnableToRegisterName;
                        object[]          objArray = new object[] { str2 };
                        viewNodeManager.OnException(viewNode1, new InstanceBuilderException(string.Format(currentCulture, instanceBuilderUnableToRegisterName, objArray), argumentException, viewNode1.DocumentNode, viewNode), false);
                    }
                }
            }
        }