This project has moved and is read-only. For the latest updates, please go here.

How to show and updated property based on another property.

Nov 12, 2012 at 11:33 PM
Edited Nov 12, 2012 at 11:54 PM

Hi, i can not use my object directly with the propertygrid, instead i need to use a wrapper like this (this is not problem it's by design).

 

....
Figure2DLibrary.BasicFigures.Rectangle rec = new Figure2DLibrary.BasicFigures.Rectangle(new Node2D(0,0));
CustomBasicFigureWrapper obj = new CustomBasicFigureWrapper(rec);
_propertyGrid.SelectedObject = obj;
....

public class CustomBasicFigureWrapper
{
    private CustomBasicFigure figure;

    public CustomBasicFigureWrapper(CustomBasicFigure pfigure)
    {
        this.figure = pfigure;
    }
               
    [Category( "General" )]
    [DisplayName( "Author" )]
    [Description( "Allows to set the creator of this instance of the figure." )]
    public string Author
    {
        get { return figure.Author; }
        set { figure.Author = value; }
    }

    [Category("Parameters")]
    [DisplayName("Height")]
    [Description("Sets the height parameter.")]
    public double Height
    {
        get { return figure.GetParameterValueByName("h"); }
        set
        {
            figure.SetParameterValueByName("h", value);
            // HERE: HOW TO MAKE THE AREA PROPERTY (below) GET REFRESHED IN THE PROPERTY GRID?
        }
    }

    [Category("Geometric Properties")]
    [DisplayName("Area")]
    [Description("Shows the area surrounded by the figure.")]
    public double Area
    {
        get { return figure.GetArea( ); }
    }
}

 

As you can see, the "height" parameter can be set in the propertyGrid, but how do i make the Area property gets refreshed?

Any ideas?

Nov 13, 2012 at 3:38 PM

Anybody??

Nov 13, 2012 at 4:04 PM

Implement the INotifyPropertyChanged interface on your wrapper, and raise the PropertyChanged event with "Area" when your Height get modified, in your setter, just like you wrote.

Nov 15, 2012 at 2:02 PM

Thanks, it works now!!!