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

Grouping

2 Answers 53 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Daenur
Top achievements
Rank 1
Daenur asked on 25 Jan 2012, 03:29 PM

I'd like to group some properties in one node with general name. I do e.PropertyDefinition.GroupName = "Name" in AutoGeneratingPropertyDefinition(), but... nothing!

Can you write code of sample?

2 Answers, 1 is accepted

Sort by
0
Branko
Top achievements
Rank 1
answered on 03 Feb 2012, 02:55 PM
Hello Daenur,

I know how to group properties in xaml, I don't know is this what you where looking for.
But I am also interested how to make Grupe Name based on Attribute description, not in xaml !? Also if you know how to make Description for property with attribute not in xaml please share.

<telerik:RadPropertyGrid AutoGeneratePropertyDefinitions="False" Item="{Binding Path="Your path to binding element"}">
  <telerik:RadPropertyGrid.PropertyDefinitions>
 
    <telerik:PropertyDefinition DisplayName="Name of your property" GroupName="Name">
 
      <telerik:PropertyDefinition.EditorTemplate>
        <DataTemplate>
          <TextBox Text="{Binding ToSomething}" />
        </DataTemplate>
      </telerik:PropertyDefinition.EditorTemplate>
    </telerik:PropertyDefinition>
  </telerik:RadPropertyGrid.PropertyDefinitions>
</telerik:RadPropertyGrid>

Thank you,
Best regards,
Branko
0
Daenur
Top achievements
Rank 1
answered on 07 Feb 2012, 11:24 AM

This is example:

[AttributeUsage(AttributeTargets.Property, Inherited = true)]
    public class StrategyPropertyAttribute : Attribute
    {
        private bool show;
        private string displayName;
        private string description;
  
        #region Properties
  
        public bool Show
        {
            get { return this.show; }
        }
  
        public string DisplayName
        {
            get { return this.displayName; }
            set { this.displayName = value; }
        }
  
        public string Description
        {
            get { return this.description; }
            set { this.description = value; }
        }
  
        #endregion
  
        public StrategyPropertyAttribute(bool show)
        {
            this.show = show;
  
            this.displayName = string.Empty;
            this.description = string.Empty;
        }
    }

[StrategyPropertyAttribute(true, DisplayName = "Length of JMA")]
        public int JmaLength
        {
            get
            {
                return (this.jmaSeries != null) ? this.jmaSeries.Length : 0;
            }
            set
            {
                if (this.jmaSeries != null)
                    this.jmaSeries.Length = value;
            }
        }

private void rpgStrategyParams_AutoGeneratingPropertyDefinition(object sender, AutoGeneratingPropertyDefinitionEventArgs e)
        {
            PropertyInfo pi = ((Telerik.Windows.Controls.RadPropertyGrid)sender).Item.GetType().GetProperty(e.PropertyDefinition.DisplayName);
            if (pi != null)
            {
                StrategyPropertyAttribute attr = pi.GetAttribute<StrategyPropertyAttribute>(true);
  
                if (attr != null)
                {
                    if (attr.Show == true)
                    {
                        if (attr.DisplayName != null)
                            e.PropertyDefinition.DisplayName = attr.DisplayName;
  
                        if (attr.Description != null)
                            e.PropertyDefinition.Description = attr.Description;
  
                        e.PropertyDefinition.GroupName = "Group"; // !!! DOESN'T WORK!!! WHY ???
                    }
                    else
                    {
                        e.Cancel = true;
                    }
                }
                else
                {
                    e.Cancel = true;
                }
            }
        }

Developers, please answer to why this code does not work?


e.PropertyDefinition.GroupName = "Group"; // !!! DOESN'T WORK!!! WHY ???

Tags
PropertyGrid
Asked by
Daenur
Top achievements
Rank 1
Answers by
Branko
Top achievements
Rank 1
Daenur
Top achievements
Rank 1
Share this question
or