コード例 #1
0
        public PropertyGridDataProvider(PropertyGrid grid, object data)
        {
            if (grid == null)
                throw new ArgumentNullException("grid");

            if (data == null)
                throw new ArgumentNullException("data");

            Grid = grid;
            Data = data;
            Properties = new ObservableCollection<PropertyGridProperty>();
            ScanProperties();
        }
コード例 #2
0
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            var property = item as PropertyGridProperty;

            if (property == null)
            {
                return(base.SelectTemplate(item, container));
            }

            DataTemplate propTemplate = PropertyGridOptionsAttribute.SelectTemplate(property, item, container);

            if (propTemplate != null)
            {
                return(propTemplate);
            }

            if (_propertyGrid == null)
            {
                _propertyGrid = container.GetVisualSelfOrParent <PropertyGrid>();
            }

            if (_propertyGrid.ValueEditorTemplateSelector != null && _propertyGrid.ValueEditorTemplateSelector != this)
            {
                DataTemplate template = _propertyGrid.ValueEditorTemplateSelector.SelectTemplate(item, container);
                if (template != null)
                {
                    return(template);
                }
            }

            foreach (PropertyGridDataTemplate template in DataTemplates)
            {
                if (Filter(template, property))
                {
                    continue;
                }

                if (template.IsCollection.HasValue && template.IsCollection.Value)
                {
                    if (string.IsNullOrWhiteSpace(template.CollectionItemPropertyType) && template.DataTemplate != null)
                    {
                        return(template.DataTemplate);
                    }

                    if (property.CollectionItemPropertyType != null)
                    {
                        foreach (Type type in template.ResolvedCollectionItemPropertyTypes)
                        {
                            if (IsAssignableFrom(type, property.CollectionItemPropertyType, template, property))
                            {
                                return(template.DataTemplate);
                            }
                        }
                    }
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(template.PropertyType) && template.DataTemplate != null)
                    {
                        return(template.DataTemplate);
                    }

                    foreach (Type type in template.ResolvedPropertyTypes)
                    {
                        if (IsAssignableFrom(type, property.PropertyType, template, property))
                        {
                            return(template.DataTemplate);
                        }
                    }
                }
            }
            return(base.SelectTemplate(item, container));
        }
コード例 #3
0
        private static void IsReadOnlyPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            PropertyGrid grid = (PropertyGrid)source;

            grid.PropertiesSource.Source = grid.PropertiesSource.Source;
        }