RadColorEditor not setting value when object implements INotifyPropertyChanged

4 posts, 0 answers
  1. Guy
    Guy avatar
    16 posts
    Member since:
    Mar 2012

    Posted 11 May Link to this post

    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;
    }

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    370 posts

    Posted 13 May Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Guy
    Guy avatar
    16 posts
    Member since:
    Mar 2012

    Posted 13 May in reply to Dilyan Traykov Link to this post

    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.
  5. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    370 posts

    Posted 16 May Link to this post

    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.
Back to Top