Exemple #1
0
        // IsExpanded DP

        private static void OnIsExpandedChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            SubPropertyEditor theThis = obj as SubPropertyEditor;

            if (theThis == null)
            {
                return;
            }

            bool          newIsExpanded     = (bool)e.NewValue;
            PropertyEntry containedProperty = theThis.PropertyEntry;

            // Store the new expansion state
            if (containedProperty != null)
            {
                PropertyState state = PropertyStateContainer.Instance.GetPropertyState(
                    ModelUtilities.GetCachedSubPropertyHierarchyPath(containedProperty));
                state.SubPropertiesExpanded = newIsExpanded;
            }

            // If we are expanded but we never exposed the sub-properties to anyone before,
            // fire a signal saying that a list of sub-properties may be now available, so that
            // UI DataBindings refresh themselves
            if (newIsExpanded == true &&
                theThis._exposedSubProperties == false)
            {
                theThis.FireSubPropertiesListChangedEvents();
            }
        }
        // <summary>
        // Convert the specified value to a string
        // </summary>
        // <param name="valueToConvert"></param>
        // <returns></returns>
        protected override string ConvertValueToString(object valueToConvert)
        {
            string stringValue = string.Empty;

            if (valueToConvert == null)
            {
                if (typeof(IList).IsAssignableFrom(this.ParentProperty.PropertyType))
                {
                    stringValue = Resources.PropertyEditing_DefaultCollectionStringValue;
                }
                else if (EditorUtilities.IsNullableEnumType(this.ParentProperty.PropertyType))
                {
                    // PS 107537: Special case handling when converting a nullable enum type to a string.
                    return(EditorUtilities.NullString);
                }
                return(stringValue);
            }
            else if ((stringValue = valueToConvert as string) != null)
            {
                return(stringValue);
            }

            TypeConverter typeConverter = this.ParentModelPropertyEntry.Converter;

            if (valueToConvert is Array)
            {
                stringValue = Resources.PropertyEditing_DefaultArrayStringValue;
            }
            else if (valueToConvert is IList ||
                     valueToConvert is ICollection ||
                     ModelUtilities.ImplementsICollection(valueToConvert.GetType()) ||
                     ModelUtilities.ImplementsIList(valueToConvert.GetType()))
            {
                stringValue = Resources.PropertyEditing_DefaultCollectionStringValue;
            }
            else if (valueToConvert is IEnumerable)
            {
                stringValue = Resources.PropertyEditing_DefaultEnumerableStringValue;
            }
            else if (typeConverter != null && typeConverter.CanConvertTo(typeof(string)))
            {
                stringValue = typeConverter.ConvertToString(null, XamlCultureInfo, valueToConvert);
            }
            else
            {
                stringValue = valueToConvert.ToString();
            }

            return(stringValue ?? string.Empty);
        }
Exemple #3
0
        private void RestoreIsExpandedState()
        {
            bool          newIsExpanded = false;
            PropertyEntry property      = this.PropertyEntry;

            if (property != null)
            {
                PropertyState state = PropertyStateContainer.Instance.GetPropertyState(
                    ModelUtilities.GetCachedSubPropertyHierarchyPath(property));
                newIsExpanded = state.SubPropertiesExpanded;
            }

            this.IsExpanded       = newIsExpanded;
            _exposedSubProperties = false;
        }
        private static Type FindCommonType(IEnumerable <ModelItem> modelItems)
        {
            Type commonType = null;

            if (modelItems != null)
            {
                foreach (ModelItem selectedItem in modelItems)
                {
                    if (commonType == null)
                    {
                        commonType = selectedItem.ItemType;
                    }
                    else
                    {
                        commonType = ModelUtilities.GetCommonAncestor(commonType, selectedItem.ItemType);
                    }
                }
            }

            return(commonType);
        }
        private static IEnumerable <IList <ModelProperty> > GetMergedPropertiesCore(PropertyExpander expander)
        {
            Dictionary <string, IList <ModelProperty> > counter = new Dictionary <string, IList <ModelProperty> >();

            int containerCounter = 0;

            foreach (IEnumerable <ModelProperty> properties in expander)
            {
                if (properties == null)
                {
                    yield break;
                }

                foreach (ModelProperty property in properties)
                {
                    IList <ModelProperty> existingModelPropertiesForProperty;
                    if (!counter.TryGetValue(property.Name, out existingModelPropertiesForProperty))
                    {
                        if (containerCounter == 0)
                        {
                            existingModelPropertiesForProperty = new List <ModelProperty>(expander.ContainerCount);
                            counter[property.Name]             = existingModelPropertiesForProperty;
                        }
                        else
                        {
                            // This property has not been encountered yet in the previous objects,
                            // so skip it altogether.
                            continue;
                        }
                    }

                    if (existingModelPropertiesForProperty.Count < containerCounter)
                    {
                        // There has been a ModelItem in the list that didn't have this property,
                        // so delete any record of it and skip it in the future.
                        counter.Remove(property.Name);
                        continue;
                    }

                    // Verify that the properties are equivalent
                    if (containerCounter > 0 &&
                        !ModelUtilities.AreEquivalent(
                            existingModelPropertiesForProperty[containerCounter - 1], property))
                    {
                        // They are not, so scrap this property altogether
                        counter.Remove(property.Name);
                        continue;
                    }

                    existingModelPropertiesForProperty.Add(property);
                }

                containerCounter++;
            }

            foreach (KeyValuePair <string, IList <ModelProperty> > pair in counter)
            {
                // Once again, if there is a property that is not shared by all
                // selected items, ignore it
                if (pair.Value.Count < containerCounter)
                {
                    continue;
                }

                // We should not set the same instance to multiple properties,
                // so ignore types that are not value type or string in case of multi-selection
                if (pair.Value.Count > 1 && !(pair.Value[0].PropertyType.IsValueType || pair.Value[0].PropertyType.Equals(typeof(string))))
                {
                    continue;
                }

                yield return((IList <ModelProperty>)pair.Value);
            }
        }