示例#1
0
 public static DocumentNode FindNamedElement(DocumentNode behaviorNode, string elementName)
 {
     if (!string.IsNullOrEmpty(elementName))
     {
         DocumentNodeNameScope containingNameScope = behaviorNode.FindContainingNameScope();
         if (containingNameScope == null)
         {
             return((DocumentNode)null);
         }
         DocumentNode node = containingNameScope.FindNode(elementName);
         if (node != null)
         {
             return(node);
         }
     }
     else
     {
         if (ProjectNeutralTypes.BehaviorTriggerAction.IsAssignableFrom((ITypeId)behaviorNode.Type))
         {
             return(BehaviorHelper.ValidateNodeTypeAndGetParent(BehaviorHelper.ValidateNodeTypeAndGetParent(BehaviorHelper.ValidateNodeTypeAndGetParent((DocumentNode)behaviorNode.Parent, ProjectNeutralTypes.BehaviorTriggerActionCollection), ProjectNeutralTypes.BehaviorTriggerBase), ProjectNeutralTypes.BehaviorTriggerCollection));
         }
         if (ProjectNeutralTypes.BehaviorTriggerBase.IsAssignableFrom((ITypeId)behaviorNode.Type))
         {
             return(BehaviorHelper.ValidateNodeTypeAndGetParent((DocumentNode)behaviorNode.Parent, ProjectNeutralTypes.BehaviorTriggerCollection));
         }
     }
     return((DocumentNode)null);
 }
        protected override void ModifyValue(PropertyReference propertyReference, object valueToSet, SceneNode.Modification modification, int index)
        {
            base.ModifyValue(propertyReference, valueToSet, modification, index);
            if (!this.IsInDocument)
            {
                return;
            }
            SceneNode sourceNode = (SceneNode)null;
            bool      flag       = this.IsSet(BehaviorEventTriggerBaseNode.BehaviorSourceObjectProperty) == PropertyState.Set;
            int       num        = (int)this.IsSet(BehaviorEventTriggerBaseNode.BehaviorSourceNameProperty);

            if (propertyReference.LastStep.Equals((object)BehaviorEventTriggerBaseNode.BehaviorSourceObjectProperty))
            {
                this.ViewModel.Document.OnUpdatedEditTransaction();
                if (modification == SceneNode.Modification.SetValue)
                {
                    sourceNode = this.ViewModel.CreateSceneNode(this.GetComputedValue(propertyReference));
                }
                else if (modification == SceneNode.Modification.ClearValue)
                {
                    sourceNode = BehaviorHelper.FindNamedElement((SceneNode)this, this.SourceName);
                }
            }
            else if (!flag && propertyReference.LastStep.Equals((object)BehaviorEventTriggerBaseNode.BehaviorSourceNameProperty))
            {
                sourceNode = BehaviorHelper.FindNamedElement((SceneNode)this, valueToSet as string);
            }
            BehaviorEventTriggerNode.FixUpEventNameImpl(this, sourceNode);
        }
示例#3
0
 public static SceneNode FindTargetElement(BehaviorTargetedTriggerActionNode goToStateNode)
 {
     if (!string.IsNullOrEmpty(goToStateNode.TargetName))
     {
         return(BehaviorHelper.FindNamedElement((SceneNode)goToStateNode, goToStateNode.TargetName));
     }
     return(goToStateNode.ViewModel.ActiveEditingContainer);
 }
示例#4
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);
        }
示例#5
0
 public static SceneNode FindNamedElement(SceneNode behaviorNode, string elementName)
 {
     if (behaviorNode != null)
     {
         DocumentNode namedElement = BehaviorHelper.FindNamedElement(behaviorNode.DocumentNode, elementName);
         if (namedElement != null)
         {
             return(behaviorNode.ViewModel.GetSceneNode(namedElement));
         }
     }
     return((SceneNode)null);
 }
        private static void FixUpEventNameImpl(BehaviorEventTriggerNode eventTriggerNode, SceneNode sourceNode)
        {
            if (sourceNode == null)
            {
                return;
            }
            IEnumerable <EventInformation> eventsForType = EventInformation.GetEventsForType((ITypeResolver)eventTriggerNode.ProjectContext, sourceNode.Type, MemberType.LocalEvent);

            if (!Enumerable.Any <EventInformation>(eventsForType, (Func <EventInformation, bool>)(info => info.EventName.Equals(eventTriggerNode.EventName, StringComparison.Ordinal))))
            {
                bool flag = false;
                DefaultEventAttribute defaultEventAttribute = TypeUtilities.GetAttribute <DefaultEventAttribute>(sourceNode.TargetType);
                if (defaultEventAttribute != null && !string.IsNullOrEmpty(defaultEventAttribute.Name) && (TriggerSourceInformation)Enumerable.SingleOrDefault <EventInformation>(eventsForType, (Func <EventInformation, bool>)(eventInfo => eventInfo.EventName == defaultEventAttribute.Name)) != (TriggerSourceInformation)null)
                {
                    eventTriggerNode.SetValue(BehaviorEventTriggerNode.EventNameProperty, (object)defaultEventAttribute.Name);
                    flag = true;
                }
                if (!flag && Enumerable.Any <EventInformation>(eventsForType, (Func <EventInformation, bool>)(info => info.EventName.Equals("Loaded", StringComparison.Ordinal))))
                {
                    eventTriggerNode.SetValue(BehaviorEventTriggerNode.EventNameProperty, (object)"Loaded");
                }
                else
                {
                    eventTriggerNode.ClearValue(BehaviorEventTriggerNode.EventNameProperty);
                }
            }
            ISceneNodeCollection <SceneNode> collectionForProperty = eventTriggerNode.Parent.GetCollectionForProperty(BehaviorHelper.BehaviorTriggersProperty);
            BehaviorTriggerBaseNode          matchingTriggerNode   = BehaviorHelper.FindMatchingTriggerNode(eventTriggerNode.DocumentNode, collectionForProperty);

            if (matchingTriggerNode == null || matchingTriggerNode.Equals((object)eventTriggerNode))
            {
                return;
            }
            for (int index = eventTriggerNode.Actions.Count - 1; index >= 0; --index)
            {
                BehaviorTriggerActionNode action = (BehaviorTriggerActionNode)eventTriggerNode.Actions[index];
                BehaviorHelper.ReparentAction(collectionForProperty, (BehaviorTriggerBaseNode)eventTriggerNode, matchingTriggerNode, action);
            }
            collectionForProperty.Remove((SceneNode)eventTriggerNode);
        }
        public static bool IsTypeCompatible(SceneNode sceneNode, IType typeToInsert, IProperty property)
        {
            if (typeToInsert.RuntimeType == (Type)null || !sceneNode.ProjectContext.PlatformMetadata.IsSupported((ITypeResolver)sceneNode.ProjectContext, (ITypeId)typeToInsert) || PlatformTypes.UserControl.IsAssignableFrom((ITypeId)sceneNode.Type) && PropertySceneInsertionPoint.ContentProperty.Equals((object)property) && sceneNode.ViewModel.RootNode != sceneNode || (PlatformTypes.Window.IsAssignableFrom((ITypeId)typeToInsert) || PlatformTypes.Page.IsAssignableFrom((ITypeId)typeToInsert) || !property.TargetType.IsAssignableFrom(sceneNode.TargetType) || PlatformTypes.IsEffectType((ITypeId)typeToInsert) && property.PropertyType.Equals((object)PlatformTypes.Object)))
            {
                return(false);
            }
            if (property.PropertyType.IsAssignableFrom((ITypeId)typeToInsert))
            {
                return(true);
            }
            if (!sceneNode.ProjectContext.IsCapabilitySet(PlatformCapability.SupportsAutoTabItemWrapping) && ProjectNeutralTypes.TabControl.IsAssignableFrom((ITypeId)sceneNode.TrueTargetTypeId) && (PlatformTypes.FrameworkElement.IsAssignableFrom((ITypeId)typeToInsert) && !ProjectNeutralTypes.TabItem.IsAssignableFrom((ITypeId)typeToInsert)))
            {
                return(false);
            }
            if (property.Equals((object)BehaviorHelper.BehaviorsProperty) && ProjectNeutralTypes.Behavior.IsAssignableFrom((ITypeId)typeToInsert) || property.Equals((object)BehaviorHelper.BehaviorTriggersProperty) && (ProjectNeutralTypes.BehaviorTriggerAction.IsAssignableFrom((ITypeId)typeToInsert) || ProjectNeutralTypes.BehaviorTriggerBase.IsAssignableFrom((ITypeId)typeToInsert)))
            {
                return(BehaviorHelper.IsSceneNodeValidHost(sceneNode, typeToInsert));
            }
            Type genericCollectionType = CollectionAdapterDescription.GetGenericCollectionType(PlatformTypeHelper.GetPropertyType(property));

            return(genericCollectionType != (Type)null && sceneNode.ProjectContext.GetType(genericCollectionType).IsAssignableFrom((ITypeId)typeToInsert) || PlatformTypes.UIElementCollection.Equals((object)property.PropertyType) && PlatformTypes.UIElement.IsAssignableFrom((ITypeId)typeToInsert) || (PlatformTypes.FlowDocument.IsAssignableFrom((ITypeId)property.PropertyType) || PlatformTypes.InlineCollection.IsAssignableFrom((ITypeId)property.PropertyType) || PlatformTypes.BlockCollection.IsAssignableFrom((ITypeId)property.PropertyType)) && (PlatformTypes.UIElement.IsAssignableFrom((ITypeId)typeToInsert) && (bool)sceneNode.ViewModel.ProjectContext.GetCapabilityValue(PlatformCapability.SupportsInlineUIContainer)) || (PlatformTypes.ItemCollection.Equals((object)property.PropertyType) || ItemsControlElement.ItemsProperty.Equals((object)property)));
        }
示例#8
0
        private static DocumentNode ResolveTargetFromBinding(DocumentNode actionNode, DocumentCompositeNode bindingNode)
        {
            string valueAsString = bindingNode.GetValueAsString(BindingSceneNode.ElementNameProperty);

            return(BehaviorHelper.FindNamedElement(actionNode, valueAsString));
        }
示例#9
0
 public static void CreateAndSetElementNameBinding(SceneNodeProperty sceneNodeProperty, SceneNode nodeToTarget)
 {
     BehaviorHelper.CreateAndSetElementNameBinding(sceneNodeProperty.PropertyName, nodeToTarget, (Action <BindingSceneNode>)(bindingNode => sceneNodeProperty.SetValue((object)bindingNode.DocumentNode)));
 }
示例#10
0
 public static void CreateAndSetElementNameBinding(IPropertyId property, SceneNode node, SceneNode nodeToTarget)
 {
     BehaviorHelper.CreateAndSetElementNameBinding(property.Name, nodeToTarget, (Action <BindingSceneNode>)(bindingNode => node.SetValueAsSceneNode(property, (SceneNode)bindingNode)));
 }
示例#11
0
 public static bool IsPropertyBehaviorCommand(IProperty property)
 {
     return(BehaviorHelper.IsPropertyBehaviorCommand(property.DeclaringType, property.PropertyType));
 }
示例#12
0
        public static BehaviorTriggerBaseNode FindMatchingTriggerNode(DocumentNode candidate, ISceneNodeCollection <SceneNode> triggerNodes)
        {
            DocumentCompositeNode triggerNode1 = candidate as DocumentCompositeNode;

            if (triggerNode1 != null)
            {
                foreach (BehaviorTriggerBaseNode behaviorTriggerBaseNode in (IEnumerable <SceneNode>)triggerNodes)
                {
                    if (behaviorTriggerBaseNode.Type.Equals((object)triggerNode1.Type))
                    {
                        DocumentCompositeNode triggerNode2 = (DocumentCompositeNode)behaviorTriggerBaseNode.DocumentNode;
                        if (!object.ReferenceEquals((object)triggerNode2, (object)candidate) && BehaviorHelper.CompareTriggerNodes(triggerNode1, triggerNode2))
                        {
                            return(behaviorTriggerBaseNode);
                        }
                    }
                }
            }
            return((BehaviorTriggerBaseNode)null);
        }
示例#13
0
 public static bool IsPropertyBehaviorCommand(PropertyReferenceProperty property)
 {
     return(BehaviorHelper.IsPropertyBehaviorCommand(property.DeclaringTypeId, property.PropertyTypeId));
 }