The properties are not displayed if the class implements ICustomTypeDescriptor

3 posts, 0 answers
  1. saravanan M
    saravanan M avatar
    2 posts
    Member since:
    Sep 2009

    Posted 28 Sep 2011 Link to this post

    Properties are not displayed in the propertygrid if the class implements ICustomTypeDescriptor. Why?
    --

    /// <summary>
        /// Interaction logic for Myobjects.xaml
        /// </summary>
        public partial class Myobjects : Page
        {
            public Myobjects()
            {
                InitializeComponent();
     
                radPropertyGrid1.AutoGeneratingPropertyDefinition += new EventHandler<Telerik.Windows.Controls.Data.PropertyGrid.AutoGeneratingPropertyDefinitionEventArgs>(radPropertyGrid1_AutoGeneratingPropertyDefinition);
                 
                radPropertyGrid1.Item = new Variable();
                 
            }
     
            void radPropertyGrid1_AutoGeneratingPropertyDefinition(object sender, Telerik.Windows.Controls.Data.PropertyGrid.AutoGeneratingPropertyDefinitionEventArgs e)
            {
                AttributeCollection attributes = TypeDescriptor.GetProperties(typeof(Variable))[e.PropertyDefinition.DisplayName].Attributes;
                BrowsableAttribute browsable = attributes[typeof(BrowsableAttribute)] as BrowsableAttribute;
                if (browsable != null)
                {
                    e.Cancel = !browsable.Browsable;
                }
     
                //CategoryAttribute category = attributes[typeof(CategoryAttribute)] as CategoryAttribute;
                //if (category.Category == "Common")
                //{
                //   e.Cancel = false;
                //}
     
            }
        }
     
        public class Variable : ICustomTypeDescriptor,  INotifyPropertyChanged
        {
            [Browsable(false)]
            [Category("Common")]
            public int Id { get; set; }
            [Category("Common")]
            public string Name { get; set; }
     
            [XmlAttribute("mandatoryCondition")]
            [Category("Required Field")]
            public string MandatoryCondition { get; set; }
     
            [XmlAttribute("mandatoryConditionMessage")]
            [Category("Required Field")]
            public string MandatoryConditionMessage { get; set; }
     
            /// <summary>
            /// Datatype of the Variable
            /// </summary>
            private DataType dataType = DataType.String;
            [XmlAttribute("dataType")]
            [Category("Common")]
            public DataType DataType
            {
                get
                {
                    return this.dataType;
                }
                set
                {
                    this.dataType = value;
                    NotifyPropertyChanged("DataType");
                }
            }
     
            #region ICustomTypeDescriptor Members
            public AttributeCollection GetAttributes()
            {
                return TypeDescriptor.GetAttributes(this, true);
            }
            public string GetClassName()
            {
                return TypeDescriptor.GetClassName(this, true);
            }
            public string GetComponentName()
            {
                return null;
            }
            public TypeConverter GetConverter()
            {
                return TypeDescriptor.GetConverter(this, true);
            }
            public EventDescriptor GetDefaultEvent()
            {
                return TypeDescriptor.GetDefaultEvent(this, true);
            }
            public PropertyDescriptor GetDefaultProperty()
            {
                return TypeDescriptor.GetDefaultProperty(this, true);
            }
            public object GetEditor(Type editorBaseType)
            {
                return null;
            }
            public EventDescriptorCollection GetEvents(Attribute[] attributes)
            {
                return TypeDescriptor.GetEvents(this, attributes, true);
            }
            public EventDescriptorCollection GetEvents()
            {
                return TypeDescriptor.GetEvents(this, true);
            }
            public object GetPropertyOwner(PropertyDescriptor pd)
            {
                return this;
            }
            public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
            {
                return this.GetProperties();
            }
     
            // Method implemented to expose mandatory field properties conditionally, depending on DataType property
            public PropertyDescriptorCollection GetProperties()
            {
                var props = new PropertyDescriptorCollection(null);
     
                foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(this, true))
                {
                    if (prop.Category == "Common" && this.DataType != DataType.String)
                        continue;
                    if (prop.Category == "Range" && (this.DataType != DataType.Integer && this.DataType != DataType.Float))
                        continue;
                    if (prop.Category == "Required Field")
                        continue;
                    props.Add(prop);
                }
     
                return props;
            }
            #endregion
     
            #region INotifyPropertyChanged Members
            public event PropertyChangedEventHandler PropertyChanged;
     
            private void NotifyPropertyChanged(String info)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(info));
                }
            }
            #endregion
        }
     
        public enum DataType
        {
            String,
            Integer,
            Float,
            Boolean,
            Date
        }



  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 03 Oct 2011 Link to this post

    Hi Saravanan M,

    There appears to be an issue with RadPropertyGrid's ICustomTypeDescriptor support. Thank you for reporting it. I have updated your Telerik points status accordingly. We will do our best to fix it in shortest terms (1 - 2 weeks). I will notify you as soon as the issue is resolved.

    All the best,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Sebastian
    Sebastian avatar
    12 posts
    Member since:
    Oct 2010

    Posted 14 Mar 2013 Link to this post

    Is the problem resolved?
    (Telerik Version: 2012.2.725.40)

    I need that, but is not work.

    Update: I resolved the problem. It was not by telerik. :-)
Back to Top