public static string GetUserFriendlyDescription(DocumentCompositeNode expressionNode, DocumentNode parentNode)
 {
     if (DocumentNodeUtilities.IsDynamicResource((DocumentNode)expressionNode) || DocumentNodeUtilities.IsStaticResource((DocumentNode)expressionNode))
     {
         DocumentNode          resourceKey           = ResourceNodeHelper.GetResourceKey(expressionNode);
         DocumentPrimitiveNode documentPrimitiveNode = resourceKey as DocumentPrimitiveNode;
         DocumentCompositeNode expressionNode1       = resourceKey as DocumentCompositeNode;
         if (documentPrimitiveNode != null && documentPrimitiveNode.Value != null)
         {
             return(documentPrimitiveNode.Value.ToString());
         }
         if (expressionNode1 != null && DocumentNodeUtilities.IsMarkupExtension((DocumentNode)expressionNode1))
         {
             return(XamlExpressionSerializer.GetUserFriendlyDescription(expressionNode1, (DocumentNode)expressionNode));
         }
     }
     else if (DocumentNodeUtilities.IsStaticResource((DocumentNode)expressionNode))
     {
         DocumentPrimitiveNode documentPrimitiveNode = expressionNode.Properties[StaticExtensionProperties.MemberProperty] as DocumentPrimitiveNode;
         if (documentPrimitiveNode != null)
         {
             return(documentPrimitiveNode.Value.ToString());
         }
     }
     return(XamlExpressionSerializer.GetStringFromExpression((DocumentNode)expressionNode, parentNode));
 }
Exemplo n.º 2
0
 protected bool DoesStyleOrTemplateApply(IPropertyId styleOrTemplateProperty, DocumentNode value)
 {
     if (PlatformTypes.FrameworkElement.IsAssignableFrom((ITypeId)this.Type))
     {
         IType templateTargetType1 = DocumentNodeUtilities.GetStyleOrTemplateTargetType(value);
         Type  type = templateTargetType1 != null ? templateTargetType1.RuntimeType : (Type)null;
         Type  c    = this.TargetElement.ProjectContext.MetadataFactory.GetMetadata(this.Type.RuntimeType).GetStylePropertyTargetType(styleOrTemplateProperty);
         if (type == (Type)null)
         {
             return(true);
         }
         if (StyleNode.BasedOnProperty.Equals((object)styleOrTemplateProperty))
         {
             StyleNode styleNode = this.TargetElement as StyleNode;
             if (styleNode != null)
             {
                 IType templateTargetType2 = DocumentNodeUtilities.GetStyleOrTemplateTargetType(styleNode.DocumentNode);
                 c = templateTargetType2 != null ? templateTargetType2.RuntimeType : (Type)null;
             }
         }
         if (c == (Type)null && ControlStylingOperations.DoesPropertyAffectRoot((IPropertyId)this.TargetProperty))
         {
             c = this.Type.RuntimeType;
         }
         if (c != (Type)null && !type.IsAssignableFrom(c))
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 3
0
        public override bool Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
        {
            TemplateBindingInstanceBuilderBase.CheckForInvalidBinding(viewNode);
            bool flag = base.Instantiate(context, viewNode);

            if (context.RootTargetTypeReplacement != null && context.IsSerializationScope)
            {
                ViewNode viewNode1 = StyleControlTemplateHelper.FindContainingControlTemplate(viewNode);
                if (viewNode1 != null)
                {
                    ViewNode viewNode2 = StyleControlTemplateHelper.FindStyleTemplateOwningViewNode(viewNode1);
                    if (viewNode2 == null || viewNode2 == context.ViewNodeManager.Root)
                    {
                        DocumentCompositeNode documentNode = viewNode.DocumentNode as DocumentCompositeNode;
                        if (documentNode != null && DocumentNodeUtilities.IsTemplateBinding(documentNode))
                        {
                            IMemberId valueAsMember = DocumentNodeHelper.GetValueAsMember(documentNode, KnownProperties.TemplateBindingPropertyProperty);
                            if (valueAsMember != null)
                            {
                                IProperty replacementProperty = context.RootTargetTypeReplacement.GetReplacementProperty(valueAsMember as IProperty);
                                if (replacementProperty != null && replacementProperty is DependencyPropertyReferenceStep && replacementProperty != valueAsMember)
                                {
                                    DocumentCompositeNode instance = (DocumentCompositeNode)viewNode.Instance;
                                    instance.Properties[KnownProperties.TemplateBindingPropertyProperty] = context.DocumentContext.CreateNode(PlatformTypes.DependencyProperty, new DocumentNodeMemberValue(replacementProperty));
                                }
                            }
                        }
                    }
                }
            }
            return(flag);
        }
Exemplo n.º 4
0
 public static bool DoesPropertyApply(SceneNode sceneNode, ReferenceStep referenceStep, SceneNode valueNode, out ReferenceStep appliedReferenceStep)
 {
     appliedReferenceStep = sceneNode.DesignerContext.PropertyManager.FilterProperty(sceneNode, referenceStep);
     if (appliedReferenceStep == null)
     {
         return(false);
     }
     if (DocumentNodeUtilities.IsStyleOrTemplate(appliedReferenceStep.PropertyType))
     {
         DocumentNode node = valueNode.DocumentNode;
         if (node.Type.IsExpression)
         {
             node = new ExpressionEvaluator(sceneNode.ViewModel.DocumentRootResolver).EvaluateExpression(sceneNode.DocumentNodePath, valueNode.DocumentNode);
         }
         if (node == null || !DocumentNodeUtilities.IsStyleOrTemplate(node.Type) || !appliedReferenceStep.PropertyType.IsAssignableFrom((ITypeId)node.Type))
         {
             return(false);
         }
         IType templateTargetType = DocumentNodeUtilities.GetStyleOrTemplateTargetType(node);
         Type  propertyTargetType = sceneNode.Metadata.GetStylePropertyTargetType((IPropertyId)appliedReferenceStep);
         if (templateTargetType != null && propertyTargetType != (Type)null && !templateTargetType.RuntimeType.IsAssignableFrom(propertyTargetType))
         {
             return(false);
         }
     }
     return(true);
 }
        public override SceneNode GenerateConverter()
        {
            IDocumentContext documentContext = this.valueConverter.DocumentContext;
            DocumentNode     keyNode         = (DocumentNode)documentContext.CreateNode(this.DisplayName);

            return(this.valueConverter.ViewModel.GetSceneNode((DocumentNode)DocumentNodeUtilities.NewStaticResourceNode(documentContext, keyNode)));
        }
Exemplo n.º 6
0
 private static void FindAllReferencedResources(DocumentNode node, List <DocumentNode> foundResources, Stack <DocumentNodePath> resourceReferenceTree, ResourceHelper.PostOrderOperation postOrderOperation)
 {
     foreach (DocumentNode documentNode1 in node.SelectDescendantNodes(new Predicate <DocumentNode>(ResourceHelper.FilterResources)))
     {
         DocumentNodePath context1 = new DocumentNodePath(node.DocumentRoot.RootNode, documentNode1);
         resourceReferenceTree.Push(context1);
         DocumentNode documentNode2 = (DocumentNode)null;
         if (DocumentNodeUtilities.IsDynamicResource(documentNode1))
         {
             foreach (DocumentNodePath context2 in resourceReferenceTree)
             {
                 documentNode2 = new ExpressionEvaluator((IDocumentRootResolver)context2.Node.Context).EvaluateExpression(context2, documentNode1);
                 if (documentNode2 != null)
                 {
                     break;
                 }
             }
         }
         else
         {
             documentNode2 = new ExpressionEvaluator((IDocumentRootResolver)context1.Node.Context).EvaluateExpression(context1, documentNode1);
         }
         if (documentNode2 != null && !ResourceHelper.IsResourceCached(documentNode2, foundResources))
         {
             foundResources.Add(documentNode2);
             ResourceHelper.FindAllReferencedResources(documentNode2, foundResources, resourceReferenceTree, postOrderOperation);
             if (postOrderOperation != null)
             {
                 postOrderOperation(documentNode2);
             }
         }
         resourceReferenceTree.Pop();
     }
 }
Exemplo n.º 7
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));
                    }
                }
            }
        }
Exemplo n.º 8
0
 protected virtual bool IsValueValidForVerification(DocumentNode valueNode)
 {
     if (!DocumentNodeUtilities.IsBinding(valueNode) && !DocumentNodeUtilities.IsTemplateBinding(valueNode))
     {
         return(!DocumentNodeUtilities.IsStaticExtension(valueNode));
     }
     return(false);
 }
Exemplo n.º 9
0
        protected DocumentNode GetReferentialPropertyValueAsDocumentNode(DocumentCompositeNode compositeNode)
        {
            DocumentNode documentNode = compositeNode.Properties[this.ReferentialProperty];

            if (documentNode != null && DocumentNodeUtilities.IsResource(documentNode))
            {
                documentNode = ExpressionEvaluator.EvaluateExpression(documentNode);
            }
            return(documentNode);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
 private object InternalGetAmbientValue(ReferenceStep property, SceneNode targetNode)
 {
     AmbientPropertyManager.AmbientPropertyValue ambientPropertyValue = this.GetAmbientPropertyValue(property);
     if (ambientPropertyValue != null)
     {
         if (ambientPropertyValue.Value == DependencyProperty.UnsetValue)
         {
             return(ambientPropertyValue.DefaultValue);
         }
         DocumentNode node = ambientPropertyValue.Value as DocumentNode;
         if (node == null)
         {
             return(DependencyProperty.UnsetValue);
         }
         if (targetNode == null && (DocumentNodeUtilities.IsStaticResource(node) || DocumentNodeUtilities.IsDynamicResource(node) || DocumentNodeUtilities.IsTemplateBinding(node)))
         {
             return(ambientPropertyValue.DefaultValue);
         }
         DocumentCompositeNode documentCompositeNode = node as DocumentCompositeNode;
         if (DocumentNodeUtilities.IsStaticResource(node) || DocumentNodeUtilities.IsDynamicResource(node))
         {
             DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(documentCompositeNode);
             bool         flag        = new ExpressionEvaluator((IDocumentRootResolver)targetNode.ProjectContext).EvaluateResource(targetNode.DocumentNodePath, DocumentNodeUtilities.IsStaticResource(node) ? ResourceReferenceType.Static : ResourceReferenceType.Dynamic, resourceKey) != null;
             if (!flag)
             {
                 object instance = targetNode.ViewModel.CreateInstance(new DocumentNodePath(resourceKey, resourceKey));
                 if (instance != null)
                 {
                     flag = targetNode.ViewModel.FindResource(instance) != null;
                 }
             }
             if (!flag)
             {
                 return(ambientPropertyValue.DefaultValue);
             }
         }
         else if (DocumentNodeUtilities.IsTemplateBinding(node))
         {
             ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator((IDocumentRootResolver)targetNode.ProjectContext);
             if (documentCompositeNode == null || expressionEvaluator.EvaluateTemplateBinding(targetNode.DocumentNodePath, documentCompositeNode) == null)
             {
                 return(ambientPropertyValue.DefaultValue);
             }
         }
         return((object)node);
     }
     if (targetNode == null || !object.Equals(ambientPropertyValue.DefaultValue, targetNode.GetDefaultValueAsWpf((IPropertyId)property)))
     {
         return(ambientPropertyValue.DefaultValue);
     }
     return(DependencyProperty.UnsetValue);
 }
Exemplo n.º 12
0
        public override void SetValueToTemplateBinding(SceneNodeProperty propertyKey, ReferenceStep referenceStep)
        {
            SceneViewModel viewModel = this.ViewModel;

            if (viewModel == null)
            {
                return;
            }
            DocumentNode documentNode = (DocumentNode)DocumentNodeUtilities.NewTemplateBindingNode(this.RepresentativeNode, (IPropertyId)referenceStep, propertyKey.Reference);

            using (viewModel.AnimationEditor.DeferKeyFraming())
                this.SetValue((PropertyReferenceProperty)propertyKey, (object)documentNode);
        }
Exemplo n.º 13
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);
        }
        private static void ReplaceTemplateTargetType(DocumentNode root, IList <DocumentCompositeNode> resources, IType targetType)
        {
            DocumentCompositeNode node = root as DocumentCompositeNode;

            if (node == null)
            {
                return;
            }
            DocumentCompositeNode parent = root.Parent;

            if (parent != null && PlatformTypes.Setter.IsAssignableFrom((ITypeId)parent.Type) && (parent.TypeResolver.ResolveProperty(SetterSceneNode.TargetNameProperty) == null || parent.Properties[SetterSceneNode.TargetNameProperty] == null) && (ControlStylingOperations.DoesPropertyAffectRoot((IPropertyId)root.GetValueProperty()) && parent.Properties[SetterSceneNode.ValueProperty] == root))
            {
                if (PlatformTypes.ControlTemplate.IsAssignableFrom((ITypeId)root.Type))
                {
                    node.Properties[ControlTemplateElement.TargetTypeProperty] = (DocumentNode)node.Context.CreateNode(PlatformTypes.Type, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)targetType));
                }
                else if (DocumentNodeUtilities.IsDynamicResource(root) || DocumentNodeUtilities.IsStaticResource(root))
                {
                    DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(node);
                    if (resourceKey != null && resources != null)
                    {
                        foreach (DocumentCompositeNode entryNode in (IEnumerable <DocumentCompositeNode>)resources)
                        {
                            if (resourceKey.Equals(ResourceNodeHelper.GetResourceEntryKey(entryNode)))
                            {
                                DocumentCompositeNode documentCompositeNode = entryNode.Properties[DictionaryEntryNode.ValueProperty] as DocumentCompositeNode;
                                if (documentCompositeNode != null)
                                {
                                    if (PlatformTypes.ControlTemplate.IsAssignableFrom((ITypeId)documentCompositeNode.Type))
                                    {
                                        documentCompositeNode.Properties[ControlTemplateElement.TargetTypeProperty] = (DocumentNode)documentCompositeNode.Context.CreateNode(PlatformTypes.Type, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)targetType));
                                        break;
                                    }
                                    break;
                                }
                                break;
                            }
                        }
                    }
                }
            }
            if (parent != null && DocumentNodeUtilities.IsStyleOrTemplate(root.Type))
            {
                return;
            }
            foreach (DocumentNode root1 in node.ChildNodes)
            {
                ReplaceStyleTemplateCommand.ReplaceTemplateTargetType(root1, resources, targetType);
            }
        }
Exemplo n.º 15
0
 private IEnumerable <SceneNode> FilteredResourceEnumerator(SceneNode pivot)
 {
     if (DocumentNodeUtilities.IsStaticResource(pivot.DocumentNode) || DocumentNodeUtilities.IsDynamicResource(pivot.DocumentNode))
     {
         yield return(pivot);
     }
     else
     {
         DocumentNode parent = (DocumentNode)pivot.DocumentNode.Parent;
         if (parent != null && parent.TargetType == typeof(DictionaryEntry))
         {
             yield return(pivot.ViewModel.GetSceneNode(parent));
         }
     }
 }
Exemplo n.º 16
0
        public DocumentNode CreateResourceReference(IDocumentContext documentContext, DocumentCompositeNode resourceNode, bool useStaticResource)
        {
            DocumentNode resourceEntryKey = ResourceNodeHelper.GetResourceEntryKey(resourceNode);

            if (resourceEntryKey == null)
            {
                return((DocumentNode)null);
            }
            DocumentNode keyNode = resourceEntryKey.Clone(documentContext);

            if (useStaticResource)
            {
                return((DocumentNode)DocumentNodeUtilities.NewStaticResourceNode(documentContext, keyNode));
            }
            return((DocumentNode)DocumentNodeUtilities.NewDynamicResourceNode(documentContext, keyNode));
        }
Exemplo n.º 17
0
        protected bool BindsTwoWayByDefault(SceneNode targetNode, ReferenceStep targetProperty)
        {
            DependencyPropertyReferenceStep propertyReferenceStep = targetProperty as DependencyPropertyReferenceStep;

            if (propertyReferenceStep == null)
            {
                return(false);
            }
            Type targetType = targetNode.TargetType;

            if (DocumentNodeUtilities.IsStyleOrTemplate(targetNode.Type))
            {
                targetType = DocumentNodeUtilities.GetStyleOrTemplateTargetType(targetNode.DocumentNode).RuntimeType;
            }
            return(propertyReferenceStep.BindsTwoWayByDefault(targetType));
        }
Exemplo n.º 18
0
        private BindingSceneNode CreateFallbackBind(SceneViewModel viewModel, string bindingPath, SceneNode targetNode, IProperty targetProperty)
        {
            BindingSceneNode binding = BindingSceneNode.Factory.Instantiate(viewModel);

            if (this.ResourceKey != null)
            {
                DocumentNode keyNode = this.ResourceKey.Clone(viewModel.Document.DocumentContext);
                binding.Source = (DocumentNode)DocumentNodeUtilities.NewStaticResourceNode(viewModel.Document.DocumentContext, keyNode);
            }
            if (bindingPath.Length > 0)
            {
                binding.XPath = bindingPath;
            }
            using (targetNode.ViewModel.AnimationEditor.DeferKeyFraming())
                targetNode.SetBinding((IPropertyId)targetProperty, binding);
            return(binding);
        }
Exemplo n.º 19
0
        public override bool Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
        {
            IPropertyId           sitePropertyKey;
            DocumentPrimitiveNode documentNode = viewNode.DocumentNode as DocumentPrimitiveNode;

            if (documentNode != null)
            {
                DocumentNodeStringValue value = documentNode.Value as DocumentNodeStringValue;
                if (value != null)
                {
                    if (viewNode.Parent == null || !viewNode.IsProperty)
                    {
                        sitePropertyKey = null;
                    }
                    else
                    {
                        sitePropertyKey = viewNode.SitePropertyKey;
                    }
                    IPropertyId propertyProperty = sitePropertyKey;
                    if (viewNode.Parent != null)
                    {
                        IPropertyValueTypeMetadata metadata = viewNode.Parent.DocumentNode.Type.Metadata as IPropertyValueTypeMetadata;
                        IPropertyValueTypeMetadata propertyValueTypeMetadatum = metadata;
                        if (metadata != null)
                        {
                            propertyProperty = propertyValueTypeMetadatum.PropertyProperty;
                        }
                    }
                    if (this.ShouldUseDesignTimeUri(propertyProperty))
                    {
                        Uri uri  = new Uri(value.Value, UriKind.RelativeOrAbsolute);
                        Uri uri1 = viewNode.DocumentNode.Context.MakeDesignTimeUri(uri);
                        if (!context.IsSerializationScope)
                        {
                            viewNode.Instance = uri1;
                        }
                        else
                        {
                            viewNode.Instance = DocumentNodeUtilities.NewUriDocumentNode(context.DocumentContext, uri1);
                        }
                        viewNode.InstanceState = InstanceState.Valid;
                    }
                }
            }
            return(base.Instantiate(context, viewNode));
        }
Exemplo n.º 20
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);
 }
Exemplo n.º 21
0
        public override void SetValueToLocalResource(SceneNodeProperty propertyKey, LocalResourceModel localResource)
        {
            DocumentNode resourceKey = localResource.ResourceKey;

            PerformanceUtility.StartPerformanceSequence(PerformanceEvent.ApplyResource, "Apply resource.");
            SceneViewModel viewModel = this.ViewModel;

            if (viewModel != null)
            {
                IDocumentContext documentContext = viewModel.Document.DocumentContext;
                IProjectContext  projectContext  = viewModel.ProjectContext;
                DocumentNode     keyNode         = resourceKey.Clone(documentContext);
                bool             flag            = this.CanSetDynamicExpression && JoltHelper.TypeSupported((ITypeResolver)projectContext, PlatformTypes.DynamicResource);
                if (flag && this.ShouldAllowAnimation && (propertyKey.IsEnabledRecordCurrentValue && this.ViewModel.AnimationEditor.IsRecording))
                {
                    flag = false;
                }
                DocumentNode documentNode = !flag ? (DocumentNode)DocumentNodeUtilities.NewStaticResourceNode(documentContext, keyNode) : (DocumentNode)DocumentNodeUtilities.NewDynamicResourceNode(documentContext, keyNode);
                using (this.ShouldAllowAnimation ? (IDisposable)null : viewModel.AnimationEditor.DeferKeyFraming())
                {
                    string description = string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.PropertyChangeUndoDescription, new object[1]
                    {
                        (object)((PropertyEntry)propertyKey).get_PropertyName()
                    });
                    if (viewModel.Document.IsEditable)
                    {
                        using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(description))
                        {
                            this.SetValue((PropertyReferenceProperty)propertyKey, (object)documentNode);
                            bool         isMixed;
                            DocumentNode valueAsDocumentNode = this.GetLocalValueAsDocumentNode(propertyKey, GetLocalValueFlags.CheckKeyframes, out isMixed);
                            if (!isMixed && valueAsDocumentNode != null)
                            {
                                Microsoft.Expression.DesignSurface.Utility.ResourceHelper.EnsureReferencedResourcesAreReachable(localResource.ResourceNode, valueAsDocumentNode);
                            }
                            editTransaction.Commit();
                        }
                    }
                }
            }
            PerformanceUtility.EndPerformanceSequence(PerformanceEvent.ApplyResource, "Apply resource.");
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
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);
        }
Exemplo n.º 24
0
        private void AddProperties(SceneElement targetElement, ResourceEntryItem resource, System.Windows.Controls.ItemCollection menuItems)
        {
            Type filterType = (Type)null;
            bool flag       = true;

            if (PlatformTypes.Brush.IsAssignableFrom((ITypeId)resource.Resource.Type))
            {
                filterType = typeof(Brush);
            }
            else if (PlatformTypes.DrawingImage.IsAssignableFrom((ITypeId)resource.Resource.Type))
            {
                filterType = typeof(ImageSource);
            }
            else if (PlatformTypes.PlatformsCompatible(resource.Resource.ValueNode.Type.PlatformMetadata, targetElement.Type.PlatformMetadata))
            {
                IType   styleOrTemplateType;
                ITypeId typeAndTargetType = DocumentNodeUtilities.GetStyleOrTemplateTypeAndTargetType(resource.Resource.ValueNode, out styleOrTemplateType);
                if (typeAndTargetType != null)
                {
                    flag       = typeAndTargetType.IsAssignableFrom((ITypeId)targetElement.Type);
                    filterType = styleOrTemplateType.RuntimeType;
                }
            }
            else
            {
                flag = false;
            }
            if (!flag)
            {
                return;
            }
            int count = menuItems.Count;

            this.AddElementPropertiesWithTypeFilter(targetElement, resource, menuItems, filterType);
            if (menuItems.Count != count)
            {
                return;
            }
            this.AddElementPropertiesWithTypeFilter(targetElement, resource, menuItems, (Type)null);
        }
Exemplo n.º 25
0
        public override void SetValueToSystemResource(SceneNodeProperty propertyKey, SystemResourceModel systemResource)
        {
            PerformanceUtility.StartPerformanceSequence(PerformanceEvent.ApplyResource, "Apply system resource.");
            SceneViewModel viewModel = this.ViewModel;

            if (viewModel != null)
            {
                IDocumentContext documentContext = viewModel.Document.DocumentContext;
                IType            type            = viewModel.ProjectContext.ProjectNamespaces.GetType((IXmlNamespace)XmlNamespace.AvalonXmlNamespace, systemResource.CollectionName);
                if (type != null)
                {
                    IMember      memberId     = (IMember)type.GetMember(MemberType.LocalProperty | MemberType.Field, systemResource.ResourceName, MemberAccessTypes.Public);
                    DocumentNode documentNode = (DocumentNode)null;
                    if (memberId != null)
                    {
                        documentNode = (DocumentNode)DocumentNodeUtilities.NewDynamicResourceNode(documentContext, (DocumentNode)DocumentNodeUtilities.NewStaticNode(documentContext, memberId));
                    }
                    using (this.ShouldAllowAnimation ? (IDisposable)null : viewModel.AnimationEditor.DeferKeyFraming())
                        this.SetValue((PropertyReferenceProperty)propertyKey, (object)documentNode);
                }
            }
            PerformanceUtility.EndPerformanceSequence(PerformanceEvent.ApplyResource, "Apply resource.");
        }
        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);
        }
Exemplo n.º 27
0
        private SceneNode CreateDataSource(SceneNode target, DataSchemaNodePath bindingPath, bool isSourcePathLess)
        {
            DocumentNode resourceKey = bindingPath.Schema.DataSource.ResourceKey;

            if (resourceKey == null)
            {
                if (!isSourcePathLess && !string.IsNullOrEmpty(bindingPath.Path))
                {
                    return((SceneNode)null);
                }
                DocumentNode documentNode   = bindingPath.Schema.DataSource.DocumentNode;
                IProjectItem designDataFile = DesignDataHelper.GetDesignDataFile(documentNode);
                DocumentNode node;
                if (designDataFile != null)
                {
                    node = DesignDataHelper.CreateDesignDataExtension(designDataFile, target.DocumentContext);
                }
                else
                {
                    if (PlatformTypes.FrameworkElement.IsAssignableFrom((ITypeId)bindingPath.Schema.DataSource.DocumentNode.Type))
                    {
                        return((SceneNode)null);
                    }
                    node = documentNode.Clone(target.DocumentContext);
                }
                return(target.ViewModel.GetSceneNode(node));
            }
            if (!this.EnsureDataSourceReachable(target, bindingPath.Schema.DataSource))
            {
                return((SceneNode)null);
            }
            BindingSceneNode bindingSceneNode = BindingSceneNode.Factory.Instantiate(target.ViewModel);
            DocumentNode     keyNode          = resourceKey.Clone(target.DocumentContext);

            bindingSceneNode.Source = (DocumentNode)DocumentNodeUtilities.NewStaticResourceNode(keyNode.Context, keyNode);
            return((SceneNode)bindingSceneNode);
        }
Exemplo n.º 28
0
        public static void PrepareContentPresenter(ContentPresenterElement element)
        {
            IDocumentContext documentContext = element.DocumentContext;

            element.SetLocalValue(BaseFrameworkElement.HorizontalAlignmentProperty, (DocumentNode)DocumentNodeUtilities.NewTemplateBindingNode(element.DocumentNode, ControlElement.HorizontalContentAlignmentProperty));
            element.SetLocalValue(BaseFrameworkElement.VerticalAlignmentProperty, (DocumentNode)DocumentNodeUtilities.NewTemplateBindingNode(element.DocumentNode, ControlElement.VerticalContentAlignmentProperty));
            if (element.IsSnapsToDevicePixelsSupported)
            {
                element.SetLocalValue(Base2DElement.SnapsToDevicePixelsProperty, (DocumentNode)DocumentNodeUtilities.NewTemplateBindingNode(element.DocumentNode, Base2DElement.SnapsToDevicePixelsProperty));
            }
            if (!element.IsRecognizesAccessKeySupported)
            {
                return;
            }
            element.SetLocalValue(ContentPresenterElement.RecognizesAccessKeyProperty, (object)true);
        }
Exemplo n.º 29
0
 protected void SetToResourceInternal(PropertyReference propertyReference, LocalResourceModel resourceModel)
 {
     using (SceneEditTransaction editTransaction = this.ViewModel.CreateEditTransaction(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.PropertySetUndo, new object[1]
     {
         (object)this.TargetProperty.Name
     })))
     {
         IDocumentContext documentContext       = this.ViewModel.Document.DocumentContext;
         DocumentNode     keyNode               = resourceModel.ResourceKey.Clone(documentContext);
         DocumentNode     resourceExtensionNode = !(propertyReference[0] is DependencyPropertyReferenceStep) || !JoltHelper.TypeSupported((ITypeResolver)this.ViewModel.ProjectContext, PlatformTypes.DynamicResource) ? (DocumentNode)DocumentNodeUtilities.NewStaticResourceNode(documentContext, keyNode) : (DocumentNode)DocumentNodeUtilities.NewDynamicResourceNode(documentContext, keyNode);
         this.TargetElement.SetValue(propertyReference, (object)resourceExtensionNode);
         Microsoft.Expression.DesignSurface.Utility.ResourceHelper.EnsureReferencedResourcesAreReachable(resourceModel.ResourceNode, resourceExtensionNode);
         editTransaction.Commit();
     }
 }
Exemplo n.º 30
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);
        }