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

hide a property

7 Answers 148 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Aziz
Top achievements
Rank 1
Aziz asked on 26 Apr 2012, 03:12 PM
If i bind the propery grid to a custom class is there some type of data annotation i can set on a property so that that property is not displayed?

such as:


public class RoleProperties : NotifiedClass
    {
        private string _name;
        private bool _canUpload;
        private bool _canPublish;
        private bool _canDelete;
        private bool _canEdit;
        private bool _canPreview;
 
       [PropertyVisibility(false)]
        public string Name
        {
            get { return _name; }
            set { _name = value;
            OnPropertyChanged("Name");}
        }
        public bool CanUpload
        {
            get { return _canUpload; }
            set { _canUpload = value; OnPropertyChanged("CanUpload"); }
        }
        public bool CanPublish
        {
            get { return _canPublish; }
            set { _canPublish = value; OnPropertyChanged("CanPublish"); }
        }
        public bool CanDelete
        {
            get { return _canDelete; }
            set { _canDelete = value; OnPropertyChanged("CanDelete"); }
        }
        public bool CanEdit
        {
            get { return _canEdit; }
            set { _canEdit = value; OnPropertyChanged("CanEdit"); }
        }
        public bool CanPreview
        {
            get { return _canPreview; }
            set { _canPreview = value; OnPropertyChanged("CanPreview"); }
        }
    }

7 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 26 Apr 2012, 03:34 PM
Hello,

Yes, there is. RadPropertyGrid supports the Browsable attribute. Here is an example that illustrates RadPropertyGrid support for several property attributes.

Greetings,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Aziz
Top achievements
Rank 1
answered on 01 May 2012, 02:40 PM
I did follow your example and set browsable to true and it worked for that example but not all cases.

here is where it does not work. i have my property grid declared as such:

<telerik:RadPropertyGrid Item="{Binding Path=ActiveShow, ElementName=mainControl, Mode=TwoWay}"
SearchBoxVisibility
="Collapsed" LabelColumnWidth="75" NestedPropertiesVisibility="Visible"
DescriptionPanelVisibility="Collapsed"/>

ActiveShow is represented by a custom class like such:

private string name;
        private string description;
        private string aspectRatio;
        private ObservableCollection<Region> regions;
 
        public ShowTemplate()
        {
            regions = new ObservableCollection<Region>();
        }
           
        [DataMember]
        [Display(Order=1)]
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
                OnPropertyChanged("Name");
            }
        }
 
        [DataMember]
        [Display(Order = 2)]
        public string Description
        {
            get
            {
                return description;
            }
            set
            {
                description = value;
                OnPropertyChanged("Description");
            }
        }
 
        [DataMember]
        [Display(Order = 7)]
        public string AspectRatio
        {
            get
            {
                return aspectRatio;
            }
            set
            {
                aspectRatio = value;
                OnPropertyChanged("AspectRatio");
            }
        }
 
        [DataMember]
        [Display(Order = 8)]
        public ObservableCollection<Region> Regions
        {
            get { return regions; }
            set
            {
                regions = value;
                OnPropertyChanged("Regions");
            }
        }

The problem becomes with the Regions property of this class. The region property is a collection of Regions defined as such:

public class Region : NotifiedClass
    {
        public Region()
        {
            playlists = new ObservableCollection<Playlist>();
        }
 
        private int id;
        private string name;
        private float height;
        private float width;
        private float canvasTop;
        private float canvasLeft;
        private int showID;
        private string color;
        private ObservableCollection<Playlist> playlists;
 
        [Browsable(false)]       
        [DataMember]       
        public int ID
        {
            get
            {
                return id;
            }
            set
            {
                id = value;
                OnPropertyChanged("ID");
            }
        }       
        [DataMember]
         
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
                OnPropertyChanged("Name");
            }
        }
         
        [DataMember]
         
        public float Height
        {
            get
            {
                return height;
            }
            set
            {
                height = value;
                OnPropertyChanged("Height");
            }
        }
         
        [DataMember]
         
        public float Width
        {
            get
            {
                return width;
            }
            set
            {
                width = value;
                OnPropertyChanged("Width");
            }
        }
         
        [DataMember]
        [Display (Name = "Top")]
        public float CanvasTop
        {
            get
            {
                return canvasTop;
            }
            set
            {
                canvasTop = value;
                OnPropertyChanged("CanvasTop");
            }
        }
         
        [DataMember]
        [Display(Name = "Left")]
        public float CanvasLeft
        {
            get
            {
                return canvasLeft;
            }
            set
            {
                canvasLeft = value;
                OnPropertyChanged("CanvasLeft");
            }
        }
         
         
        [DataMember]       
        public int ShowID
        {
            get
            {
                return showID;
            }
            set
            {
                showID = value;
                OnPropertyChanged("ShowID");
            }
        }
         
        [Browsable(false)]
        [DataMember]       
        public string Color
        {
            get
            {
                return color;
            }
            set
            {
                color = value;
                OnPropertyChanged("Color");
            }
        }
 
        public ObservableCollection<Playlist> Playlists
        {
            get { return playlists; }
            set
            {
                playlists = value;
                OnPropertyChanged("Playlists");
            }
        }
    }


the problem i have is not matter what set on region properties they always show in the property grid. A prime example being the Color property of Region. I dont want it to show but even with browsable(false) it still shows in the property grid. I have also tried setting Display(AutoGeneratedField=false) on these properties to no effect.

How do i get this to work save having to manually define the property Row Definitions in xaml?
0
Maya
Telerik team
answered on 02 May 2012, 08:05 AM
Hi Jacob,

We did have an issue with respecting Browsable attribute for nested properties. However, it has already been resolved in our internal builds. Please download the latest one and let me know whether you still have any problems.  

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Aziz
Top achievements
Rank 1
answered on 02 May 2012, 01:20 PM
please confirm the internal build version you are speaking of as i think i am currently up to date
0
Maya
Telerik team
answered on 02 May 2012, 01:23 PM
Hi Jacob,

Actually, the fix has been available for a couple of weeks now. So, if you are working with our latest internal build (from this Monday - 30.04.2012), you should not get the undesired behavior. Do you still have some troubles ?
 

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Aziz
Top achievements
Rank 1
answered on 02 May 2012, 01:37 PM
I just downloaded RadControls_for_Silverlight4_2012_1_0430_DEV_hotfix and replaced all binaries in my project with those ones. Testing now with the above code. Behaviour is still not as expected.

to start with in the property grid my property regions shows and is 'expandable' as expected. however it shows the object type beside it, this should be hidden.

When i expand regions it shows count 2 (again because its an observable collection, count should be hidden)

it then shows items and indicates it can expand but when i click on the plus nothing is there....
0
Maya
Telerik team
answered on 07 May 2012, 08:46 AM
Hello Jacob,

The fix I was referring to is the one with setting Browsable attribute for nested properties. Considering expanding the 'Item" property of the Regions - indeed I managed to reproduce it with our latest version. I will research the case and let you know once I could provide more information on it. As for the Count property - you can hide it as follows:

private void myPropertyGrid_AutoGeneratingPropertyDefinition(object sender, Telerik.Windows.Controls.Data.PropertyGrid.AutoGeneratingPropertyDefinitionEventArgs e)
        {
            if(e.PropertyDefinition.Binding.Path.Path == "Count")
            {
                e.Cancel = true;
            }
        }

Will that approach meet your requirements ? 

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
PropertyGrid
Asked by
Aziz
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Aziz
Top achievements
Rank 1
Maya
Telerik team
Share this question
or