示例#1
0
        private void Meta_Modified(object sender, EventArgs e)
        {
            PropertyGridEditor editor = sender as PropertyGridEditor;

            if (editor == null)
            {
                return;
            }

            List <object> items = new List <object>();

            if (Items != null && Items.Count > 0)
            {
                items.AddRange(Items.OfType <object>());
            }
            else if (DataContext != null)
            {
                items.Add(DataContext);
            }

            if (items.Count == 0)
            {
                return;
            }

            foreach (object obj in items)
            {
                PropertyInfo prop = obj.GetType().GetProperty(editor.Name);
                if (prop == null)
                {
                    continue;
                }
                prop.SetValue(obj, editor.Data);
            }
        }
示例#2
0
        private void ParseProperties(IEnumerable <object> items)
        {
            Clear();
            foreach (object obj in items)
            {
                foreach (PropertyInfo prop in obj.GetType().GetProperties())
                {
                    if (prop.DeclaringType == typeof(DependencyObject))
                    {
                        continue;
                    }
                    if (prop.DeclaringType == typeof(DispatcherObject))
                    {
                        continue;
                    }

                    PropertyEditorMetadataAttribute atty = prop.GetCustomAttribute <PropertyEditorMetadataAttribute>();
                    if (atty != null && atty.Hidden)
                    {
                        continue;
                    }

                    PropertyGridEditor editor = null;
                    _properties.TryGetValue(prop.Name, out editor);

                    if (editor == null)
                    {
                        editor = PropertyGridEditorFactory.GetEditor(prop.PropertyType);
                        editor.PropertyType = prop.PropertyType;
                        editor.Name         = prop.Name;
                        editor.DisplayName  = PascalCaseSplitter.Split(prop.Name);
                        editor.IsReadOnly   = prop.SetMethod == null || !prop.SetMethod.IsPublic;
                        editor.Modified    += Meta_Modified;

                        _properties.Add(prop.Name, editor);
                        Properties.Add(editor);
                    }

                    editor.Values.Add(prop.GetValue(obj, null));
                }
            }
        }
        protected static void OnDataPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PropertyGridEditor ed = ((PropertyGridEditor)d);

            ed.OnDataChanged();
        }
        protected static object OnCoercePropertyData(DependencyObject d, object baseValue)
        {
            PropertyGridEditor ed = ((PropertyGridEditor)d);

            return(ed.OnCoerceData(baseValue));
        }