public Converter(PropertyGridComboBoxExtension extension) { Extension = extension; }
protected virtual void Describe(PropertyGridProperty property, PropertyDescriptor descriptor) { if (property == null) { throw new ArgumentNullException("property"); } if (descriptor == null) { throw new ArgumentNullException("descriptor"); } property.Descriptor = descriptor; property.Name = descriptor.Name; property.PropertyType = descriptor.PropertyType; // unset by default. conversion service does the default job //property.Converter = descriptor.Converter; property.Category = string.IsNullOrWhiteSpace(descriptor.Category) || descriptor.Category.EqualsIgnoreCase(CategoryAttribute.Default.Category) ? Grid.DefaultCategoryName : descriptor.Category; property.IsReadOnly = descriptor.IsReadOnly; property.Description = descriptor.Description; property.DisplayName = descriptor.DisplayName; if (Grid.DecamelizePropertiesDisplayNames && property.DisplayName == descriptor.Name) { property.DisplayName = DecamelizationService.Decamelize(property.DisplayName); } property.IsEnum = descriptor.PropertyType.IsEnum; property.IsFlagsEnum = descriptor.PropertyType.IsEnum && Extensions.IsFlagsEnum(descriptor.PropertyType); var options = descriptor.GetAttribute <PropertyGridOptionsAttribute>(); if (options != null) { if (options.SortOrder != 0) { property.SortOrder = options.SortOrder; } property.IsEnum = options.IsEnum; property.IsFlagsEnum = options.IsFlagsEnum; } var att = descriptor.GetAttribute <DefaultValueAttribute>(); if (att != null) { property.HasDefaultValue = true; property.DefaultValue = att.Value; } else if (options != null) { if (options.HasDefaultValue) { property.HasDefaultValue = true; property.DefaultValue = options.DefaultValue; } else { string defaultValue; if (PropertyGridComboBoxExtension.TryGetDefaultValue(options, out defaultValue)) { property.DefaultValue = defaultValue; property.HasDefaultValue = true; } } } AddDynamicProperties(descriptor.Attributes.OfType <PropertyGridAttribute>(), property.Attributes); AddDynamicProperties(descriptor.PropertyType.GetAttributes <PropertyGridAttribute>(), property.TypeAttributes); }
public Converter(PropertyGridComboBoxExtension extension) { Extension = extension; }
public virtual void OnToggleButtonIsCheckedChanged(object sender, RoutedEventArgs e) { var button = e.OriginalSource as ToggleButton; if (button != null) { var item = button.DataContext as PropertyGridItem; if (item != null && item.Property != null && item.Property.IsEnum && item.Property.IsFlagsEnum) { if (button.IsChecked.HasValue) { ulong itemValue = PropertyGridComboBoxExtension.EnumToUInt64(item.Property, item.Value); ulong propertyValue = PropertyGridComboBoxExtension.EnumToUInt64(item.Property, item.Property.Value); ulong newValue; if (button.IsChecked.Value) { if (itemValue == 0) { newValue = 0; } else { newValue = propertyValue | itemValue; } } else { newValue = propertyValue & ~itemValue; } object propValue = PropertyGridComboBoxExtension.EnumToObject(item.Property, newValue); item.Property.Value = propValue; var li = button.GetVisualSelfOrParent <ListBoxItem>(); if (li != null) { ItemsControl parent = ItemsControl.ItemsControlFromItemContainer(li); if (parent != null) { if (button.IsChecked.Value && itemValue == 0) { foreach (var gridItem in parent.Items.OfType <PropertyGridItem>()) { gridItem.IsChecked = PropertyGridComboBoxExtension.EnumToUInt64(item.Property, gridItem.Value) == 0; } } else { foreach (var gridItem in parent.Items.OfType <PropertyGridItem>()) { ulong gridItemValue = PropertyGridComboBoxExtension.EnumToUInt64(item.Property, gridItem.Value); if (gridItemValue == 0) { gridItem.IsChecked = newValue == 0; continue; } gridItem.IsChecked = (newValue & gridItemValue) == gridItemValue; } } } } } } } }