private static void InitializePropertyItem(PropertyItem propertyItem, IPropertyDefinition pd)
        {
            propertyItem.ChildrenDefinitions = pd.ChildrenDefinitions;


            // Assign a shorter name, for code clarity only.
            PropertyGridUtilities.SetupDefinitionBinding(propertyItem, PropertyItem.DisplayNameProperty, pd, () => pd.DisplayName);
            PropertyGridUtilities.SetupDefinitionBinding(propertyItem, PropertyItem.DescriptionProperty, pd, () => pd.Description);
            PropertyGridUtilities.SetupDefinitionBinding(propertyItem, PropertyItem.CategoryProperty, pd, () => pd.Category);
            PropertyGridUtilities.SetupDefinitionBinding(propertyItem, PropertyItem.PropertyOrderProperty, pd, () => pd.DisplayOrder);
            PropertyGridUtilities.SetupDefinitionBinding(propertyItem, PropertyItem.AdvancedOptionsIconProperty, pd, () => pd.AdvancedOptionsIcon);
            PropertyGridUtilities.SetupDefinitionBinding(propertyItem, PropertyItem.AdvancedOptionsTooltipProperty, pd, () => pd.AdvancedOptionsTooltip);
            PropertyGridUtilities.SetupDefinitionBinding(propertyItem, PropertyItem.IsExpandableProperty, pd, () => pd.IsExpandable);

            Binding valueBinding = new Binding("Value")
            {
                Source = pd,
                Mode   = BindingMode.TwoWay
            };

            propertyItem.SetBinding(PropertyItem.ValueProperty, valueBinding);

            propertyItem.Editor = pd.GenerateEditorElement(propertyItem);

            if (pd.CommandBindings != null)
            {
                foreach (CommandBinding commandBinding in pd.CommandBindings)
                {
                    propertyItem.CommandBindings.Add(commandBinding);
                }
            }
        }
        private static void SetupDefinitionBinding <T>(
            PropertyItem propertyItem,
            DependencyProperty itemProperty,
            IPropertyDefinition pd,
            Expression <Func <T> > definitionProperty)
        {
            string  sourceProperty = ReflectionHelper.GetPropertyOrFieldName(definitionProperty);
            Binding binding        = new Binding(sourceProperty)
            {
                Source = pd,
                Mode   = BindingMode.OneWay
            };

            propertyItem.SetBinding(itemProperty, binding);
        }
        private void SetupDefinitionBinding <T>(
            PropertyItem propertyItem,
            DependencyProperty itemProperty,
            DescriptorPropertyDefinitionBase pd,
            Expression <Func <T> > definitionProperty,
            BindingMode bindingMode)
        {
            string  sourceProperty = ReflectionHelper.GetPropertyOrFieldName(definitionProperty);
            Binding binding        = new Binding(sourceProperty)
            {
                Source = pd,
                Mode   = bindingMode
            };

            propertyItem.SetBinding(itemProperty, binding);
        }
Exemple #4
0
        internal static PropertyItem CreatePropertyItem(PropertyDescriptor property, object instance, PropertyGrid grid, string bindingPath)
        {
            PropertyItem propertyItem = new PropertyItem(instance, property, grid, bindingPath);

            var binding = new Binding(bindingPath)
            {
                Source = instance,
                ValidatesOnExceptions = true,
                ValidatesOnDataErrors = true,
                Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay
            };

            propertyItem.SetBinding(PropertyItem.ValueProperty, binding);

            propertyItem.Editor = PropertyGridUtilities.GetTypeEditor(propertyItem, grid.EditorDefinitions);

            return(propertyItem);
        }