This is a migrated thread and some comments may be shown as answers.

RadColorEditor not setting value when object implements INotifyPropertyChanged

3 Answers 39 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Guy
Top achievements
Rank 1
Guy asked on 12 May 2016, 01:09 AM

With a basic RadPropertyGrid, if I set the Item to an object with a System.Windows.Media.Color property, when I pick a color in the editor, it will properly call the property setter and update Test1's Color value.

 

public class Test1
{
    public System.Windows.Media.Color Color { get; set; }
}

 

If I use the following Test2 class instead, changing the color in the property grid will not call the property setter and the value in the box will not get updated.

public class Test2 : INotifyPropertyChanged
{
    public System.Windows.Media.Color Color { get; set; }
    public event PropertyChangedEventHandler PropertyChanged;
}

3 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 13 May 2016, 09:56 AM
Hello Guy,

In order for an object to correctly notify RadPropertyGrid for changes made to it, it should correctly implement the INotifyPropertyChanged interface, similarly to:

public class Test2 : INotifyPropertyChanged
{
    private Color color;
 
    public Color Color
    {
        get
        {
            return this.color;
        }
        set
        {
            if (value != this.color)
            {
                this.color = value;
                this.OnPropertyChanged("Color");
            }
        }
    }
 
    public event PropertyChangedEventHandler PropertyChanged;
 
    protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
    {
        PropertyChangedEventHandler handler = this.PropertyChanged;
        if (handler != null)
        {
            handler(this, args);
        }
    }
 
    private void OnPropertyChanged(string propertyName)
    {
        this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
    }
}

Please let me know if this clarifies things for you.

Regards,
Dilyan Traykov
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Guy
Top achievements
Rank 1
answered on 13 May 2016, 08:19 PM
Hi Dilyan, I'm not making changes to the object and expecting to see it change in the property grid. It's the other way around: When making changes in the property grid, it doesn't propagate the changes back to the object. The bug seems specific to the RadColorEditor, RadColorPicker, etc. as it works correctly with other properties using the RadNumericUpDown.
0
Dilyan Traykov
Telerik team
answered on 16 May 2016, 01:56 PM
Hello Guy,

I'm attaching a sample project where the setter of the Color property of the Test2 object is invoked when changes in the RadPropertyGrid are made.

Could you please have a look at it and let me know if I'm missing something?
 
Regards,
Dilyan Traykov
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
PropertyGrid
Asked by
Guy
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Guy
Top achievements
Rank 1
Share this question
or