Grouping

3 posts, 0 answers
  1. Daenur
    Daenur avatar
    5 posts
    Member since:
    Mar 2006

    Posted 25 Jan 2012 Link to this post

    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. Branko
    Branko avatar
    18 posts
    Member since:
    Feb 2012

    Posted 03 Feb 2012 Link to this post

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

    Posted 07 Feb 2012 Link to this post

    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 ???

Back to Top