Inheritance: System.Windows.DependencyObject, IComparable, INotifyPropertyChanged
Esempio n. 1
0
        void InsertInPropertOrder(PropertyInformation property)
        {
            if (Properties.Count == 0)
            {
                Properties.Add(property);
                return;
            }

            if (PropertiesAreInOrder(property, Properties[0]))
            {
                Properties.Insert(0, property);
                return;
            }

            for (var i = 0; i < Properties.Count - 1; i++)
            {
                if (PropertiesAreInOrder(Properties[i], property) && PropertiesAreInOrder(property, Properties[i + 1]))
                {
                    Properties.Insert(i + 1, property);
                    return;
                }
            }

            Properties.Add(property);
        }
Esempio n. 2
0
        private void HandleNameClick(object sender, MouseButtonEventArgs e)
        {
            if (e.ClickCount == 2)
            {
                PropertyInformation property = (PropertyInformation)((FrameworkElement)sender).DataContext;

                object newTarget = null;

                if (Keyboard.Modifiers == ModifierKeys.Shift)
                {
                    newTarget = property.Binding;
                }
                else if (Keyboard.Modifiers == ModifierKeys.Control)
                {
                    newTarget = property.BindingExpression;
                }
                else if (Keyboard.Modifiers == ModifierKeys.None)
                {
                    newTarget = property.Value;
                }

                if (newTarget != null)
                {
                    PropertyInspector.DelveCommand.Execute(property, this);
                }
            }
        }
Esempio n. 3
0
        public static List <PropertyInformation> GetProperties(object obj, Predicate <PropertyDescriptor> filter)
        {
            // get the properties
            var propertyDescriptors = GetAllProperties(obj, new Attribute[] { new PropertyFilterAttribute(PropertyFilterOptions.All) });

            // filter the properties
            var props = (
                from property in propertyDescriptors
                where filter(property)
                select new PropertyInformation(obj, property, property.Name, property.DisplayName)).ToList();

            //delve path. also, issue 4919
            var extendedProps = GetExtendedProperties(obj);

            props.AddRange(extendedProps);

            // if the object is a collection, add the items in the collection as properties
            var collection = obj as ICollection;
            var index      = 0;

            if (collection != null)
            {
                foreach (var item in collection)
                {
                    var info = new PropertyInformation(item, collection, index, "this[" + index + "]");
                    index++;
                    info.Value = item;
                    props.Add(info);
                }
            }

            props.Sort();

            return(props);
        }
Esempio n. 4
0
        public static void AddEditedProperty(Dispatcher dispatcher, VisualTreeItem propertyOwner,
                                             PropertyInformation propInfo)
        {
            lock (_lock) {
                List <PropertyValueInfo> propInfoList = null;
                Dictionary <VisualTreeItem, List <PropertyValueInfo> > dispatcherList = null;

                // first get the dictionary we're using for the given dispatcher
                if (!_itemsWithEditedProperties.TryGetValue(dispatcher, out dispatcherList))
                {
                    dispatcherList = new Dictionary <VisualTreeItem, List <PropertyValueInfo> >();
                    _itemsWithEditedProperties.Add(dispatcher, dispatcherList);
                }

                // now get the property info list for the owning object
                if (!dispatcherList.TryGetValue(propertyOwner, out propInfoList))
                {
                    propInfoList = new List <PropertyValueInfo>();
                    dispatcherList.Add(propertyOwner, propInfoList);
                }

                // if we already have a property of that name on this object, remove it
                var existingPropInfo = propInfoList.FirstOrDefault(l => l.PropertyName == propInfo.DisplayName);
                if (existingPropInfo != null)
                {
                    propInfoList.Remove(existingPropInfo);
                }

                // finally add the edited property info
                propInfoList.Add(new PropertyValueInfo {
                    PropertyName  = propInfo.DisplayName,
                    PropertyValue = propInfo.Value
                });
            }
        }
Esempio n. 5
0
        private void InsertInPropertOrder(PropertyInformation property)
        {
            if (this.properties.Count == 0)
            {
                this.properties.Add(property);
                return;
            }

            if (PropertiesAreInOrder(property, this.properties[0]))
            {
                this.properties.Insert(0, property);
                return;
            }

            for (int i = 0; i < this.properties.Count - 1; i++)
            {
                if (PropertiesAreInOrder(this.properties[i], property) && PropertiesAreInOrder(property, this.properties[i + 1]))
                {
                    this.properties.Insert(i + 1, property);
                    return;
                }
            }

            this.properties.Add(property);
        }
Esempio n. 6
0
 bool PropertiesAreInOrder(PropertyInformation first, PropertyInformation last)
 {
     if (direction == ListSortDirection.Ascending)
     {
         return(first.CompareTo(last) <= 0);
     }
     return(last.CompareTo(first) <= 0);
 }
 public bool Show(PropertyInformation property)
 {
     // use a regular expression if we have one and we also have a filter string.
     if (this.filterRegex != null && !string.IsNullOrEmpty(this.FilterString))
     {
         return
             (
             this.filterRegex.IsMatch(property.DisplayName) ||
             property.Property != null && this.filterRegex.IsMatch(property.Property.PropertyType.Name)
             );
     }
     // else just check for containment if we don't have a regular expression but we do have a filter string.
     else if (!string.IsNullOrEmpty(this.FilterString))
     {
         if (property.DisplayName.ToLower().Contains(this.FilterString))
         {
             return(true);
         }
         if (property.Property != null && property.Property.PropertyType.Name.ToLower().Contains(this.FilterString))
         {
             return(true);
         }
         return(false);
     }
     // else use the filter set if we have one of those.
     else if (IsPropertyFilterSet)
     {
         if (SelectedFilterSet.IsPropertyInFilter(property.DisplayName))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     // finally, if none of the above applies
     // just check to see if we're not showing properties at their default values
     // and this property is actually set to its default value
     else
     {
         if (!this.ShowDefaults && property.ValueSource.BaseValueSource == BaseValueSource.Default)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
 }
Esempio n. 8
0
        /// <summary>
        /// 4919 + Delve
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private static IList <PropertyInformation> GetExtendedProperties(object obj)
        {
            List <PropertyInformation> props = new List <PropertyInformation>();

            if (obj != null && ResourceKeyCache.Contains(obj))
            {
                string key = ResourceKeyCache.GetKey(obj);
                PropertyInformation prop = new PropertyInformation(key, new object(), "x:Key", true);
                prop.Value = key;
                props.Add(prop);
            }

            return(props);
        }
Esempio n. 9
0
        public static List <PropertyInformation> GetProperties(object obj, Predicate <PropertyDescriptor> filter)
        {
            List <PropertyInformation> props = new List <PropertyInformation>();


            // get the properties
            List <PropertyDescriptor> propertyDescriptors = GetAllProperties(obj, new Attribute[] { new PropertyFilterAttribute(PropertyFilterOptions.All) });


            // filter the properties
            foreach (PropertyDescriptor property in propertyDescriptors)
            {
                if (filter(property))
                {
                    PropertyInformation prop = new PropertyInformation(obj, property, property.Name, property.DisplayName);
                    props.Add(prop);
                }
            }

            //delve path. also, issue 4919
            var extendedProps = GetExtendedProperties(obj);

            props.AddRange(extendedProps);


            // if the object is a collection, add the items in the collection as properties
            ICollection collection = obj as ICollection;
            int         index      = 0;

            if (collection != null)
            {
                foreach (object item in collection)
                {
                    PropertyInformation info = new PropertyInformation(item, collection, "this[" + index + "]");
                    index++;
                    info.Value = item;
                    props.Add(info);
                }
            }


            // sort the properties
            props.Sort();


            return(props);
        }
Esempio n. 10
0
        /// <summary>
        /// Delayed loading of the property inspector to avoid creating the entire list of property
        /// editors immediately after selection. Keeps that app running smooth.
        /// </summary>
        /// <param name="performInitialization"></param>
        /// <returns></returns>
        private void ProcessIncrementalPropertyAdd()
        {
            int numberToAdd = 10;

            if (this.propertiesToAdd == null)
            {
                this.propertiesToAdd = PropertyInformation.GetProperties(this.target).GetEnumerator();

                numberToAdd = 0;
            }
            int i = 0;

            for (; i < numberToAdd && this.propertiesToAdd.MoveNext(); ++i)
            {
                // iterate over the PropertyInfo objects,
                // setting the property grid's filter on each object,
                // and adding those properties to the observable collection of propertiesToSort (this.properties)
                PropertyInformation property = this.propertiesToAdd.Current;
                property.Filter = this.Filter;

                if (property.IsVisible)
                {
                    this.properties.Add(property);
                }
                allProperties.Add(property);

                // checking whether a property is visible ... actually runs the property filtering code
                if (property.IsVisible)
                {
                    property.Index = this.visiblePropertyCount++;
                }
            }

            if (i == numberToAdd)
            {
                this.processIncrementalCall.Enqueue();
            }
            else
            {
                this.propertiesToAdd = null;
            }
        }
Esempio n. 11
0
        private void HandleShowBindingErrors(object sender, ExecutedRoutedEventArgs eventArgs)
        {
            PropertyInformation propertyInformation = (PropertyInformation)eventArgs.Parameter;
            Window  window  = new Window();
            TextBox textbox = new TextBox();

            textbox.IsReadOnly   = true;
            textbox.Text         = propertyInformation.BindingError;
            textbox.TextWrapping = TextWrapping.Wrap;
            window.Content       = textbox;
            window.Width         = 400;
            window.Height        = 300;
            window.Title         = "Binding Errors for " + propertyInformation.DisplayName;
            SnoopPartsRegistry.AddSnoopVisualTreeRoot(window);
            window.Closing +=
                (s, e) =>
            {
                Window w = (Window)s;
                SnoopPartsRegistry.RemoveSnoopVisualTreeRoot(w);
            };
            window.Show();
        }
Esempio n. 12
0
		public bool Show(PropertyInformation property)
		{
			// use a regular expression if we have one and we also have a filter string.
			if (this.filterRegex != null && !string.IsNullOrEmpty(this.FilterString))
			{
				return
				(
					this.filterRegex.IsMatch(property.DisplayName) ||
					property.Property != null && this.filterRegex.IsMatch(property.Property.PropertyType.Name)
				);
			}
			// else just check for containment if we don't have a regular expression but we do have a filter string.
			else if (!string.IsNullOrEmpty(this.FilterString))
			{
				if (property.DisplayName.ToLower().Contains(this.FilterString))
					return true;
				if (property.Property != null && property.Property.PropertyType.Name.ToLower().Contains(this.FilterString))
					return true;
				return false;
			}
			// else use the filter set if we have one of those.
			else if (IsPropertyFilterSet)
			{
				if (SelectedFilterSet.IsPropertyInFilter(property.DisplayName))
					return true;
				else
					return false;
			}
			// finally, if none of the above applies
			// just check to see if we're not showing properties at their default values
			// and this property is actually set to its default value
			else
			{
				if (!this.ShowDefaults && property.ValueSource.BaseValueSource == BaseValueSource.Default)
					return false;
				else
					return true;
			}
		}
Esempio n. 13
0
        public static void AddEditedProperty( Dispatcher dispatcher, VisualTreeItem propertyOwner, PropertyInformation propInfo)
        {
            lock ( _lock )
            {
                List<PropertyValueInfo> propInfoList = null;
                Dictionary<VisualTreeItem, List<PropertyValueInfo>> dispatcherList = null;

                // first get the dictionary we're using for the given dispatcher
                if ( !_itemsWithEditedProperties.TryGetValue( dispatcher, out dispatcherList ) )
                {
                    dispatcherList = new Dictionary<VisualTreeItem, List<PropertyValueInfo>>();
                    _itemsWithEditedProperties.Add( dispatcher, dispatcherList );
                }

                // now get the property info list for the owning object
                if ( !dispatcherList.TryGetValue( propertyOwner, out propInfoList ) )
                {
                    propInfoList = new List<PropertyValueInfo>();
                    dispatcherList.Add( propertyOwner, propInfoList );
                }

                // if we already have a property of that name on this object, remove it
                var existingPropInfo = propInfoList.FirstOrDefault( l => l.PropertyName == propInfo.DisplayName );
                if ( existingPropInfo != null )
                {
                    propInfoList.Remove( existingPropInfo );
                }

                // finally add the edited property info
                propInfoList.Add( new PropertyValueInfo
                                  {
                                  	PropertyName = propInfo.DisplayName,
                                  	PropertyValue = propInfo.Value,
                                  } );
            }
        }
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            PropertyInformation property = (PropertyInformation)item;

            if (property.PropertyType.IsEnum)
            {
                return(this.EnumTemplate);
            }
            else if (property.PropertyType.Equals(typeof(bool)))
            {
                return(this.BoolTemplate);
            }
            else if (property.PropertyType.IsGenericType &&
                     Nullable.GetUnderlyingType(property.PropertyType) == typeof(bool))
            {
                return(this.BoolTemplate);
            }
            else if (typeof(Brush).IsAssignableFrom(property.PropertyType))
            {
                return(this.brushTemplate);
            }

            return(this.StandardTemplate);
        }
Esempio n. 15
0
        /// <summary>
        /// 4919 + Delve
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private static IList<PropertyInformation> GetExtendedProperties(object obj)
        {
            List<PropertyInformation> props = new List<PropertyInformation>();

            if (obj != null && ResourceKeyCache.Contains(obj))
            {
                string key = ResourceKeyCache.GetKey(obj);
                PropertyInformation prop = new PropertyInformation(key, new object(), "x:key", true);
                prop.Value = key;
                props.Add(prop);
            }

            return props;
        }
Esempio n. 16
0
        public static List<PropertyInformation> GetProperties(object obj, Predicate<PropertyDescriptor> filter)
        {
            List<PropertyInformation> props = new List<PropertyInformation>();

            // get the properties
            List<PropertyDescriptor> propertyDescriptors = GetAllProperties(obj, new Attribute[] { new PropertyFilterAttribute(PropertyFilterOptions.All) });

            // filter the properties
            foreach (PropertyDescriptor property in propertyDescriptors)
            {
                if (filter(property))
                {
                    PropertyInformation prop = new PropertyInformation(obj, property, property.Name, property.DisplayName);
                    props.Add(prop);
                }
            }

            //delve path. also, issue 4919
            var extendedProps = GetExtendedProperties(obj);
            props.AddRange(extendedProps);

            // if the object is a collection, add the items in the collection as properties
            ICollection collection = obj as ICollection;
            int index = 0;
            if (collection != null)
            {
                foreach (object item in collection)
                {
                    PropertyInformation info = new PropertyInformation(item, collection, "this[" + index + "]");
                    index++;
                    info.Value = item;
                    props.Add(info);
                }
            }

            // sort the properties
            props.Sort();

            return props;
        }
Esempio n. 17
0
		private void InsertInPropertOrder(PropertyInformation property)
		{
			if (this.properties.Count == 0)
			{
				this.properties.Add(property);
				return;
			}

			if (PropertiesAreInOrder(property, this.properties[0]))
			{
				this.properties.Insert(0, property);
				return;
			}

			for (int i = 0; i < this.properties.Count - 1; i++)
			{
				if (PropertiesAreInOrder(this.properties[i], property) && PropertiesAreInOrder(property, this.properties[i + 1]))
				{
					this.properties.Insert(i + 1, property);
					return;
				}
			}

			this.properties.Add(property);
		}
Esempio n. 18
0
		private bool PropertiesAreInOrder(PropertyInformation first, PropertyInformation last)
		{
			if (direction == ListSortDirection.Ascending)
			{
				return first.CompareTo(last) <= 0;
			}
			else
			{
				return last.CompareTo(first) <= 0;
			}
		}
Esempio n. 19
0
		private static int CompareNames(PropertyInformation one, PropertyInformation two)
		{
			// use the PropertyInformation CompareTo method, instead of the string.Compare method
			// so that collections get sorted correctly.
			return one.CompareTo(two);
		}
Esempio n. 20
0
 public static List <PropertyInformation> GetProperties(object obj)
 {
     return(PropertyInformation.GetProperties(obj, new PertinentPropertyFilter(obj).Filter));
 }
Esempio n. 21
0
 private static int CompareValueSources(PropertyInformation one, PropertyInformation two)
 {
     return(string.Compare(one.ValueSource.BaseValueSource.ToString(), two.ValueSource.BaseValueSource.ToString()));
 }
Esempio n. 22
0
 private static int CompareValues(PropertyInformation one, PropertyInformation two)
 {
     return(string.Compare(one.StringValue, two.StringValue));
 }
Esempio n. 23
0
 private static int CompareNames(PropertyInformation one, PropertyInformation two)
 {
     // use the PropertyInformation CompareTo method, instead of the string.Compare method
     // so that collections get sorted correctly.
     return(one.CompareTo(two));
 }
Esempio n. 24
0
		private static int CompareValues(PropertyInformation one, PropertyInformation two)
		{
			return string.Compare(one.StringValue, two.StringValue);
		}
Esempio n. 25
0
        /// <summary>
        /// 4919 + Delve
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private static IList<PropertyInformation> GetExtendedProperties(object obj)
        {
            List<PropertyInformation> props = new List<PropertyInformation>();

            if (obj is Style)
            {
                //string key;
                //if (StyleKeyCache.Keys.TryGetValue((Style)obj, out key))
                if (StyleKeyCache.ContainsStyle((Style)obj))
                {
                    string key = StyleKeyCache.GetKey((Style)obj);
                    PropertyInformation prop = new PropertyInformation(key, new object(), "x:key", true);
                    prop.Value = key;
                    props.Add(prop);
                }
            }

            return props;
        }
Esempio n. 26
0
		private static int CompareValueSources(PropertyInformation one, PropertyInformation two)
		{
			return string.Compare(one.ValueSource.BaseValueSource.ToString(), two.ValueSource.BaseValueSource.ToString());
		}