Default view in PropertyGrid

12 posts, 0 answers
  1. Reed
    Reed avatar
    4 posts
    Member since:
    Sep 2010

    Posted 26 Jul 2011 Link to this post

    How do I set the default, initial view for a PropertyGrid to display categorized/grouped instead of listed Alphabetically?

    There is a property (SortAndGroupVisibility) for enabling the option to change this by the end user, but I see no means to directly set this in Xaml or code behind...


  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 27 Jul 2011 Link to this post

    Hi Reed,

    We have not exposed a descent API to control the state programmatically so as a workaround I may offer the following hack :
    public MainPage()
            {
                InitializeComponent();
     
                this.RadPropertyGrid1.LayoutUpdated += new EventHandler(RadPropertyGrid1_LayoutUpdated);
                 
            }
     
            void RadPropertyGrid1_LayoutUpdated(object sender, EventArgs e)
            {
                this.RadPropertyGrid1.LayoutUpdated -= new EventHandler(RadPropertyGrid1_LayoutUpdated);
                var button = this.RadPropertyGrid1.ChildrenOfType<RadRadioButton>().Where(b=>b.Name=="groupButton").First();
                button.IsChecked = true;
            }

    * Please add an "Using Telerik.Windows.Controls" in order to get access to the ChildrenOfType<> extension method.

    Greetings,
    Pavel Pavlov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. UI for WPF is Visual Studio 2017 Ready
  4. Chris
    Chris  avatar
    42 posts
    Member since:
    Apr 2009

    Posted 25 Oct 2011 Link to this post

    Hi,
    This doesn't seem to work anymore.
    Is there a different method?
    Thanks.
     
  5. Pavel
    Pavel avatar
    8 posts
    Member since:
    Aug 2011

    Posted 17 Nov 2011 Link to this post

    I join to the issue. Is there a solution?
  6. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 17 Nov 2011 Link to this post

    Hello Pavel,

    With Q3 2011 we have introduced a new property (IsGrouped) that controls current RadPropertyGrid's state. You can set it to true in the xaml and you will have an initially grouped RadPropertyGrid.

    All the best,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  7. Paul
    Paul avatar
    4 posts
    Member since:
    Nov 2011

    Posted 17 Nov 2011 Link to this post

    I downloaded the Version: 2011.3 1116 (Nov 16, 2011) of the library. Yes, the IsGrouped property is exist, but after run code
    <TemplatesEditor:TlPropertyGrid x:Name="PART_propGrid" Grid.Row="2"
        AutoGeneratePropertyDefinitions="False"
        DescriptionPanelVisibility="Collapsed"
        LabelColumnWidth="200"
        IsGrouped="True"
        telerik:StyleManager.Theme="{StaticResource Theme}"
        SelectedObject="{Binding ElementName=PART_Diagram, Path=SelectedItem, Mode=OneWay}"/>


    where

       
    public class TlPropertyGrid : RadPropertyGrid
    {
        static TlPropertyGrid()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(TlPropertyGrid), new FrameworkPropertyMetadata(typeof(TlPropertyGrid)));
        }
     
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);
            Theme theme = StyleManager.GetTheme(this);
            Type themeType = null;
            if (theme != null)
            {
                themeType = theme.GetType();
            }
            DefaultStyleKey = new ThemeResourceKey { ElementType = typeof(RadPropertyGrid), ThemeType = themeType };
        }
     
        public object SelectedObject
        {
            get { return GetValue(SelectedObjectProperty); }
            set { SetValue(SelectedObjectProperty, value); }
        }
     
        public static readonly DependencyProperty SelectedObjectProperty =
            DependencyProperty.Register("SelectedObject", typeof(object), typeof(TlPropertyGrid), new UIPropertyMetadata(null, OnSelectedObjectChangedCallback));
     
        private static void OnSelectedObjectChangedCallback(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            var propertyGrid = sender as TlPropertyGrid;
            if (propertyGrid == null)
            {
                return;
            }
            propertyGrid.CollectProperties();
        }
     
        private void CollectProperties()
        {
            Item = SelectedObject;
            PropertyDefinitions.Clear();
           // fill PropertyDefinitions
        }
    }
    I see empty grid. The properties will show only after I click Flat mode button
  8. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 17 Nov 2011 Link to this post

    Hello Andrey,

    Please excuse me, but I think that I have misunderstood your approach. As far as I can see, you have introduced a new DependencyProperty, which you have bound to your data source and on its updating you reset PropertyGrid's Item. Would you please share with us your considerations of not binding PropertyGrid's Item property directly, instead of using this new "buffer" property?

    Kind regards,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  9. Paul
    Paul avatar
    4 posts
    Member since:
    Nov 2011

    Posted 17 Nov 2011 Link to this post

    Hi Ivan,

    This is a necessary action, because does not suit me a primitive mechanism  based on AutoGeneratingPropertyDefinition. I need more control over the filling properties based on attributes. Specifically need support ICustomTypeDescriptor, EditorAttribute, BrowsableAttribute, TypeConverter.
    Inside the AutoGeneratingPropertyDefinition handler I have not access to the property attributes. You made this property an internal. If you ask how to make a solution with

    Item="{Binding ...}
    and I could handle something like
    [SortCategoryAttribute("Appearance", 1)]
    [DisplayName("Opacity")]
    [Description("Opacity")]
    [NumberRangeAttribute(0, 1, 0.1, 2)]
    [Editor(typeof(OpacityPropertyValueEditor), typeof(PropertyValueEditor))]
    public double Opacity { get; set; }
    ,
     I'm just glad
  10. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 21 Nov 2011 Link to this post

    Hello Andrey,

    Thank you for attracting our attention to this issue. I have updated your telerik points status accordingly. A fix for it will be available in our next internal build which will be uploaded in few days.

    Regards,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  11. Branko
    Branko avatar
    18 posts
    Member since:
    Feb 2012

    Posted 03 Feb 2012 Link to this post

    Hi Andrey,

    If you have some example of using Attributes with RadPropertyGrid with release Q3 and if you can share ?. I need also to have control on properties in Property Grid. Like: Gruping, Description, NumberRange, Dependancy between properties (If property A (check box is check) then property B is editable and if not is only readable ) etc.

    Thank you.
    Regards,
    Branko
  12. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 06 Feb 2012 Link to this post

    Hi Branko,

    With our next official release (Q1 2012), which is to be released in 10-15 days, we will introduce support for various property attributes (Category, ReadOnly, Browsable, Display etc.) and ReadOnly states for both separate fields and the whole control itself. However, we have not considered native dependencies between properties as a feature of RadPropertyGrid. Would you please shed some more light on this matter, so that we could think of some workaround that would meet your requirement?

    Kind regards,
    Ivan Ivanov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  13. Pavel
    Pavel avatar
    8 posts
    Member since:
    Aug 2011

    Posted 09 Feb 2012 Link to this post

    Hi Branko,
     I hope the team realize support for the attributes in the next version but until it is not released I share my experience.
    I created own class inherits from RadPropertyGrid
    <TemplatesEditor:TlPropertyGrid x:Name="PART_propGrid"
                                                                        Editors="{StaticResource EditorTemplates}"
                                                                        AutoGeneratePropertyDefinitions="False"
                                                                        IsGrouped="True"
                                                                        DescriptionPanelVisibility="Collapsed"
                                                                        LabelColumnWidth="140"
                                                                 SelectedObject="{Binding ElementName=PART_Diagram, Path=SelectedItem, Mode=OneWay}"/>

    where
        public class TlPropertyGrid : RadPropertyGrid
        {
            static TlPropertyGrid()
            {
                DefaultStyleKeyProperty.OverrideMetadata(typeof(TlPropertyGrid), new FrameworkPropertyMetadata(typeof(TlPropertyGrid)));
            }

            protected override void OnInitialized(EventArgs e)
            {
                base.OnInitialized(e);
                Theme theme = StyleManager.GetTheme(this);
                Type themeType = null;
                if (theme != null)
                {
                    themeType = theme.GetType();
                }
                DefaultStyleKey = new ThemeResourceKey { ElementType = typeof(RadPropertyGrid), ThemeType = themeType };
            }

            public override void OnApplyTemplate()
            {
                base.OnApplyTemplate();
                var sv = GetTemplateChild("PART_ItemsScrollViewer") as ScrollViewer;
                if (sv != null)
                {
                    sv.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled);
                }
            }

            public TlDataTemplateDictionary Editors
            {
                get { return (TlDataTemplateDictionary)GetValue(EditorsProperty); }
                set { SetValue(EditorsProperty, value); }
            }

            public static readonly DependencyProperty EditorsProperty =
                DependencyProperty.Register("Editors", typeof(TlDataTemplateDictionary), typeof(TlPropertyGrid), new UIPropertyMetadata(new TlDataTemplateDictionary()));

            public object SelectedObject
            {
                get { return GetValue(SelectedObjectProperty); }
                set { SetValue(SelectedObjectProperty, value); }
            }

            public static readonly DependencyProperty SelectedObjectProperty =
                DependencyProperty.Register("SelectedObject", typeof(object), typeof(TlPropertyGrid), new UIPropertyMetadata(null, OnSelectedObjectChangedCallback));

            private static void OnSelectedObjectChangedCallback(DependencyObject sender, DependencyPropertyChangedEventArgs args)
            {
                var propertyGrid = sender as TlPropertyGrid;
                if (propertyGrid == null)
                {
                    return;
                }
                propertyGrid.CollectProperties();
            }

            private void CollectProperties()
            {
                Item = SelectedObject;
                PropertyDefinitions.Clear();
                PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(SelectedObject,
                  new Attribute[] { new PropertyFilterAttribute(PropertyFilterOptions.SetValues |
                                                          PropertyFilterOptions.UnsetValues |
                                                          PropertyFilterOptions.Valid) });
                foreach (PropertyDescriptor descr in descriptors)
                {
                    if (descr.IsBrowsable)
                    {
                        if (descr is ILookupSource)
                        {
                            var ls = (ILookupSource) descr;
                            var lpd = new LookupPropertyDefinition();
                            lpd.DisplayName = descr.DisplayName;
                            lpd.ItemsSource = ls.GetSource();
                            lpd.SelectedValuePath = ls.SelectedValuePath;
                            lpd.DisplayMemberPath = ls.DisplayMemberPath;
                            lpd.Binding = new Binding(descr.Name) {Mode = BindingMode.TwoWay};

                            #region Hack

                            var sp = lpd.GetType().GetProperty("SourceProperty",
                                                               BindingFlags.Instance | BindingFlags.NonPublic);
                            //var pd = new FictionPropertyDescriptor(typeof(string), descr.Name, null);
                            sp.SetValue(lpd, new ItemPropertyInfo(descr.Name, typeof (string), descr), null);

                            #endregion

                            PropertyDefinitions.Add(lpd);
                        }
                        else
                        {
                            var propertyInfo = new ItemPropertyInfo(descr.Name, descr.PropertyType, descr);
                            var propertyDefinition = new PropertyDefinition(propertyInfo)
                                                         {
                                                             DisplayName = descr.DisplayName,
                                                             Description = descr.Description,
                                                             Binding =
                                                                 new Binding(propertyInfo.Name) {Mode = BindingMode.TwoWay},
                                                             GroupName = descr.Category
                                                         };
                            // ReSharper disable AssignNullToNotNullAttribute
                            var editor = descr.GetEditor(typeof (PropertyValueEditor)) as PropertyValueEditor;
                            // ReSharper restore AssignNullToNotNullAttribute
                            DataTemplate dt = null;
                            if (editor != null)
                            {
                                dt = editor.InlineEditorTemplate;
                            }
                            if (editor == null)
                            {
                                var attr = (EditorRef) descr.Attributes[typeof (EditorRef)];
                                if (attr != null && Editors != null)
                                {
                                    Editors.TryGetValue(attr.EditorKey, out dt);
                                }
                            }
                            if (dt == null && propertyInfo.PropertyType == typeof(Color))
                            {
                                dt = CreateColorEditor(propertyInfo);
                            }
                            propertyDefinition.EditorTemplate = dt;
                            PropertyDefinitions.Add(propertyDefinition);
                        }
                    }
                }
            }

            private DataTemplate CreateColorEditor(ItemPropertyInfo pi)
            {
                var dt = new DataTemplate();
                var colorPickerFactory = new FrameworkElementFactory(typeof(RadColorPicker)) { Name = "cp" };
                var binding = new Binding
                {
                    Path = new PropertyPath(pi.Name),
                    Mode = BindingMode.TwoWay, // @todo need determine BindingMode
                    UpdateSourceTrigger = UpdateSourceTrigger.LostFocus
                };
                colorPickerFactory.SetBinding(RadColorPicker.SelectedColorProperty, binding);

                dt.VisualTree = colorPickerFactory;
                dt.Seal();
                return dt;
            }
        }
    For properties with combobox view I used ILookupSource interface. Now it's the only solution and it works only with hack. I didn't found any solution. The PropertyValueEditor class from WpfPropertyGrid library. Previous solution was stand on it and I reuse it.
    The EditorRefAttribute linked with the Editors property.
    For example if defined in XAML
        <TemplatesEditor:TlDataTemplateDictionary x:Key="EditorTemplates">
            <DataTemplate x:Key="ColorTemplate">
                <telerik:RadColorPicker SelectedColor="{Binding Color, Mode=TwoWay}" />
            </DataTemplate>
        </TemplatesEditor:TlDataTemplateDictionary>

    Then I can use
            [EditorRef("ColorTemplate")]
            public Color Color { get; set; }

    I hope this help,
    Pavel
Back to Top
UI for WPF is Visual Studio 2017 Ready