protected void RecalculateTemplateBindableProperties() { this.templateBindableProperties.Clear(); SceneNode[] objects = this.Objects; if (objects.Length != 1) { return; } SceneNode sceneNode = objects[0]; if (sceneNode == null || sceneNode.StoryboardContainer == null || !typeof(ControlTemplateElement).IsAssignableFrom(sceneNode.StoryboardContainer.GetType()) || !sceneNode.Platform.Metadata.IsCapabilitySet(PlatformCapability.SupportNonFrameworkElementTemplateBinding) && !PlatformTypes.FrameworkElement.IsAssignableFrom((ITypeId)sceneNode.Type)) { return; } Type targetElementType = sceneNode.StoryboardContainer.TargetElementType; if (!(targetElementType != (Type)null)) { return; } IList <TargetedReferenceStep> mergedProperties = PropertyMerger.GetMergedProperties((IEnumerable <SceneNode>) new SceneNode[1] { sceneNode.ViewModel.CreateSceneNode(targetElementType) }); IProjectContext projectContext = sceneNode.ProjectContext; foreach (TargetedReferenceStep targetedReferenceStep in (IEnumerable <TargetedReferenceStep>)mergedProperties) { DependencyPropertyReferenceStep referenceStep = targetedReferenceStep.ReferenceStep as DependencyPropertyReferenceStep; if (referenceStep != null) { bool showReadOnly = true; if (PropertyInspectorModel.IsPropertyBrowsable(objects, targetedReferenceStep, showReadOnly) && PropertyInspectorModel.IsAttachedPropertyBrowsable(objects, this.ObjectTypeId, targetedReferenceStep, (ITypeResolver)projectContext)) { this.templateBindableProperties.Add(new TemplateBindablePropertyModel(referenceStep)); } } } this.templateBindableProperties.Sort((Comparison <TemplateBindablePropertyModel>)((left, right) => string.Compare(left.PropertyName, right.PropertyName, StringComparison.CurrentCulture))); this.OnPropertyChanged("TemplateBindableProperties"); }
public void Rebuild() { foreach (PropertyBase propertyBase in this.subProperties) { propertyBase.Associated = false; } PropertyDescriptorCollection descriptorCollection = (PropertyDescriptorCollection)null; Type targetType = this.parentProperty.PropertyType; bool isMixed; DocumentNode valueAsDocumentNode = this.parentProperty.GetLocalValueAsDocumentNode(true, out isMixed); if (valueAsDocumentNode == null || !(valueAsDocumentNode is DocumentPrimitiveNode) && !valueAsDocumentNode.Type.IsBinding) { TypeConverter converterFromAttributes = MetadataStore.GetTypeConverterFromAttributes(targetType.Assembly, this.parentProperty.Attributes); if (converterFromAttributes != null) { object obj = this.parentProperty.SceneNodeObjectSet.GetValue(this.parentProperty.Reference, this.parentProperty.IsExpression ? PropertyReference.GetValueFlags.Computed : PropertyReference.GetValueFlags.Local); if (obj != null && obj != MixedProperty.Mixed) { descriptorCollection = converterFromAttributes.GetProperties(obj); targetType = obj.GetType(); } } if (descriptorCollection == null) { object component = this.parentProperty.SceneNodeObjectSet.GetValue(this.parentProperty.Reference, this.parentProperty.IsExpression ? PropertyReference.GetValueFlags.Computed : PropertyReference.GetValueFlags.Local); if (component != null && component != MixedProperty.Mixed) { descriptorCollection = TypeUtilities.GetProperties(component); targetType = component.GetType(); } } } this.objectSet.RebuildObjects(); IProjectContext projectContext = this.parentProperty.SceneNodeObjectSet.ProjectContext; if (projectContext != null && descriptorCollection != null) { SceneNode[] objects = this.objectSet.Objects; foreach (PropertyDescriptor propertyDescriptor in descriptorCollection) { ReferenceStep referenceStep = PlatformTypeHelper.GetProperty((ITypeResolver)projectContext, targetType, propertyDescriptor) as ReferenceStep; if (referenceStep != null) { TargetedReferenceStep targetedReferenceStep = new TargetedReferenceStep(referenceStep, this.objectSet.ObjectTypeId); if (PropertyInspectorModel.IsPropertyBrowsable(objects, targetedReferenceStep) && PropertyInspectorModel.IsAttachedPropertyBrowsable(objects, this.objectSet.ObjectTypeId, targetedReferenceStep, (ITypeResolver)this.parentProperty.SceneNodeObjectSet.ProjectContext)) { PropertyReference propertyReference = new PropertyReference(referenceStep); SceneNodeProperty property = this.FindProperty(propertyReference); if (property == null) { SceneNodeProperty sceneNodeProperty = this.objectSet.CreateProperty(propertyReference, referenceStep.Attributes) as SceneNodeProperty; int index = this.subProperties.BinarySearch(sceneNodeProperty, (IComparer <SceneNodeProperty>) new SceneNodePropertyCollection.PropertyNameComparer()); if (index < 0) { index = ~index; } this.subProperties.Insert(index, sceneNodeProperty); this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, (object)sceneNodeProperty, index)); } else if (!property.UpdateAndRefresh(propertyReference, referenceStep.Attributes, (Type)null)) { property.Associated = true; } } } } } for (int index = this.subProperties.Count - 1; index >= 0; --index) { if (!this.subProperties[index].Associated) { PropertyEntry propertyEntry = (PropertyEntry)this.subProperties[index]; this.subProperties[index].OnRemoveFromCategory(); this.subProperties.RemoveAt(index); this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, (object)propertyEntry, index)); } } this.OnPropertyChanged("Item[]"); }
private static bool IsPropertyBindableAsTarget(SceneNode sceneNode, ReferenceStep referenceStep, bool isDeclaringTypeBindable) { if (referenceStep.Equals((object)referenceStep.DeclaringType.Metadata.NameProperty) || (referenceStep.WriteAccess & (MemberAccessType)14) == MemberAccessType.None) { return(false); } SceneNode[] selection = new SceneNode[1] { sceneNode }; TargetedReferenceStep targetedReferenceStep = new TargetedReferenceStep(referenceStep, sceneNode.Type); if ((!PropertyInspectorModel.IsPropertyBrowsable(selection, targetedReferenceStep) || !PropertyInspectorModel.IsAttachedPropertyBrowsable(selection, sceneNode.Type, targetedReferenceStep, (ITypeResolver)sceneNode.ProjectContext)) && !referenceStep.Equals((object)ContentControlElement.ContentProperty)) { return(false); } if (referenceStep.PropertyType.IsBinding) { return(true); } object[] customAttributes = referenceStep.GetCustomAttributes(typeof(BindableAttribute), false); if (customAttributes != null && customAttributes.Length > 0) { return(((BindableAttribute)customAttributes[0]).Bindable); } return(isDeclaringTypeBindable && referenceStep is DependencyPropertyReferenceStep); }
private void AddElementPropertiesWithTypeFilter(SceneElement targetElement, ResourceEntryItem resource, System.Windows.Controls.ItemCollection menuItems, Type filterType) { SceneNode[] selection = new SceneNode[1] { (SceneNode)targetElement }; foreach (TargetedReferenceStep targetedReferenceStep in (IEnumerable <TargetedReferenceStep>)PropertyMerger.GetMergedProperties((IEnumerable <SceneNode>)selection)) { ReferenceStep referenceStep = targetedReferenceStep.ReferenceStep; if (referenceStep.Name != "Name" && PropertyInspectorModel.IsPropertyBrowsable(selection, targetedReferenceStep) && (PropertyInspectorModel.IsAttachedPropertyBrowsable(selection, targetElement.Type, targetedReferenceStep, (ITypeResolver)targetElement.ProjectContext) && PlatformTypeHelper.GetPropertyType((IProperty)referenceStep) != (Type)null) && (PlatformTypeHelper.GetPropertyType((IProperty)referenceStep).IsAssignableFrom(resource.Resource.Type.RuntimeType) && (filterType == (Type)null || filterType.IsAssignableFrom(PlatformTypeHelper.GetPropertyType((IProperty)referenceStep))))) { menuItems.Add((object)this.BuildPropertyMenuItem(targetElement, referenceStep, resource)); } } }
private static bool IsPropertyBindableAsSource(SceneNode sceneNode, ReferenceStep referenceStep) { if ((referenceStep.ReadAccess & (MemberAccessType)14) == MemberAccessType.None) { return(false); } SceneNode[] selection = new SceneNode[1] { sceneNode }; TargetedReferenceStep targetedReferenceStep = new TargetedReferenceStep(referenceStep, sceneNode.Type); return(PropertyInspectorModel.IsPropertyBrowsable(selection, targetedReferenceStep, true, true) && PropertyInspectorModel.IsAttachedPropertyBrowsable(selection, sceneNode.Type, targetedReferenceStep, (ITypeResolver)sceneNode.ProjectContext)); }