/// <summary> /// Adds a property to the UI /// </summary> /// <param name="property"></param> /// <param name="propertyMetadata"></param> private void AddProperty(InspectableProperty property, InspectablePropertyMetadata propertyMetadata, CategoryContainer container) { //Get the category of the property if its not set //CategoryContainer container = GetCategoryContainer(propertyMetadata); ValueControl valueControl; PropertyContainer propContainer; //Check if the property has a custom control if (propertyMetadata.HasCustomControl) { valueControl = propertyMetadata.CustomControlFactory.GetControl(property); } else { valueControl = controlFactory.GetControl(property); } //If the edit mode is set to on focus, create a textblock for when its not if (valueControl.EditBehaviour == EditingBehaviour.OnFocus) { TextBlock unfocusElement = controlFactory.CreateUnFocusedTextBlock(property.ReflectionData.Name, property.Target); propContainer = new PropertyContainer(propertyMetadata.Name, valueControl, unfocusElement); } else { propContainer = new PropertyContainer(propertyMetadata.Name, valueControl); } container.AddProperty(propContainer); }
public ValueControl GetControl(InspectableProperty property) { string propName = property.ReflectionData.Name; Type propType = property.ReflectionData.PropertyType; if (!property.ReflectionData.CanWrite || property.ReflectionData.GetSetMethod() == null) { return(new ValueControl(CreateDisabledTextBlock(property.ReflectionData.Name, property.Target))); } else { if (ControlProviders.ContainsKey(propType)) { return(ControlProviders[propType].GetControl(property)); } //Special case for enums if (propType.IsSubclassOf(typeof(Enum))) { if (ControlProviders.ContainsKey(typeof(Enum))) { return(ControlProviders[typeof(Enum)].GetControl(property)); } } //No Valid provides, treat as readonly/disabled return(new ValueControl(CreateDisabledTextBlock(property.ReflectionData.Name, property.Target))); } }
public SuspendableProperty(InspectableProperty property) { this.property = property; if (property.Target is INotifyPropertyChanged) { (property.Target as INotifyPropertyChanged).PropertyChanged += SuspendableProperty_PropertyChanged; } }
public static InspectablePropertyMetadata GetPropertyMetadata(InspectableProperty property) { if (!metadataCache.ContainsKey(property.ReflectionData)) { var metadata = GenerateMetaData(property); metadataCache.Add(property.ReflectionData, metadata); } return(metadataCache[property.ReflectionData]); }
private void ListenToPropertyChanged(InspectableProperty property) { var target = property.Target as INotifyPropertyChanged; if (target != null) { if (!eventPublishers.ContainsKey(target.GetHashCode())) { eventPublishers.Add(target.GetHashCode(), new WeakReference <INotifyPropertyChanged>(target)); } target.PropertyChanged += TargetObject_PropertyChanged; } }
private static InspectablePropertyMetadata GenerateMetaData(InspectableProperty property) { //Get all attributes object[] attributes = property.ReflectionData.GetCustomAttributes(false); //Check for update on prop change attribute bool updateLayout = attributes .Any(x => x.GetType() == typeof(UpdatePropListOnPropChangeAttribute)); CategoryAttribute categoryAttribute = attributes .FirstOrDefault(x => x is CategoryAttribute) as CategoryAttribute; //Set category name to the default string categoryName = String.Empty; //Change it to the value of category attribute if it exists if (categoryAttribute != null) { categoryName = categoryAttribute.Category; } else { //Do a last check for display name on the source class (target) of the property DisplayNameAttribute categoryDisplayName = property.Target.GetType() .GetFirstOrDefaultAttribute <DisplayNameAttribute>(); if (categoryDisplayName != null) { categoryName = categoryDisplayName.DisplayName; } } //If there is no category yet, should we use Target toString as category or the default if (categoryName == string.Empty) { categoryName = property.Target.ToString(); } //Get DisplayName if any string displayName = (attributes.FirstOrDefault(x => x is DisplayNameAttribute) as DisplayNameAttribute)?.DisplayName; var metaData = new InspectablePropertyMetadata(updateLayout, categoryName, property.ReflectionData); metaData.DisplayName = displayName; return(metaData); }