LOGIN    REGISTER    YOUR CART

homepage
VisualHint's blog
2022
Apr06

Smart PropertyGrid Final for .Net 6, version 4.0.1, is released

A short time after the final release of SPG for .Net 6, here is an updated version with many new methods added to the Fluent API (+ a crash fix). With it comes a completely new sample that you can find on Github, showing all possibilities of the API. Frankly, it's quite cool, and I'm sure you will give me your ideas to enhance it even more.

For the pleasure:

// FontColor property is not created because it is later added manually as a child of a Font property
.ForProperty(x => x.FontColor, config => config.FilterOut(PropertyPreFilterOutEventArgs.FilterModes.FilterOut))

.ForProperty(x => x.MyFont, config => config
    .Sorted(propertySortedIndex++)
    .Category(ReflectionCategory, 5)
    .DisplayName("Font")
    .Comment("This property content is discovered by reflection but I customized it to hide certain subproperties, add a Color property, set the booleans as checkboxes with various texts and assigned up/down buttons to Size.")
    .ChildLook<PropertyCheckboxLook>("Italic")
    .ChildLook<PropertyCheckboxLook>("Strikeout")
    .ChildLook<PropertyCheckboxLook>("Underline")
    .ChildLook<PropertyCheckboxLook>("Bold")
    .ChildFeel("Strikeout", FeelCheckbox)
    .ChildFeel("Italic", FeelCheckbox)
    .ChildFeel("Underline", FeelCheckbox)
    .ChildFeel("Bold", FeelCheckbox)
    .ChildFeel("Size", FeelEditUpDown)
    .ChildDisplayedValues("Bold", new string[] { "", "" })
    .ChildDisplayedValues("Italic", new string[] { "Yes", "No" })
    .HideChildProperties("GdiCharSet", "GdiVerticalFont", "Unit")
    .PropertyCreated((args, grid) =>
    {
        args.PropertyEnum.Property.Value.Validator = new PropertyValidatorFontSize(5.0f, 15.0f);

        // In case LazyLoading==true, the children have not been created yet, so expand the property to be sure...
        grid.ExpandProperty(args.PropertyEnum, true);

        var childEnum = args.PropertyEnum.Children;
        if (childEnum.Count > 0)
        {
            childEnum.MoveFirst();
            childEnum.Property.Comment = "Uses a UITypeEditor. By the way, you can set comments to auto-discovered subproperties...";
            childEnum.MoveNext();
            childEnum.Property.Comment = "A custom feel has been applied to this property. It is done by setting an attribute to its parent. Also a validator constrains the value between 5 and 15.";
            childEnum.Property.Value.Validator = new PropertyValidatorMinMax((Single)5.0, (Single)15.0);
            childEnum.MoveNext();

            var propEnum = grid.InsertProperty(childEnum, 150, "Color", grid.SelectedObject, "FontColor", "");
            propEnum.Property.Feel = grid.GetRegisteredFeel(FeelList);
            propEnum.Property.Look = new PropertyAlphaColorLook();
            propEnum.Property.Comment = "This color has been added to the children of the font. It uses an alpha color editor.";

            propEnum.MoveNext();
            propEnum.Property.Comment = "The text of a checkbox can be removed.";
            propEnum.MoveNext();
            propEnum.Property.Comment = "The text of a checkbox can be customized.";

            grid.ExpandProperty(args.PropertyEnum, false);
        }
    })
)

Here you can see some nice built-in methods like Sorted or ChildLook. And when you need complex customizations, you always have an handy event to go deep inside the SPG api.