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

Ignoring AutoGeneratePropertyDefinitions

4 Answers 95 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Maxim
Top achievements
Rank 1
Maxim asked on 27 Apr 2012, 12:29 PM

Why PropertyGrid generate excess properties, when AutoGeneratePropertyDefinitions is set to false?

<Window x:Class="PropertyGridTester.MainWindow"
        xmlns:PropertyGridTester="clr-namespace:PropertyGridTester"
        Title="MainWindow" Height="350" Width="525"
        mc:Ignorable="d" 
        d:DataContext="{d:DesignInstance {x:Type PropertyGridTester:MainWindowViewModel}}">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
          
        <StackPanel Grid.Column="0">
            <RadioButton Command="{Binding SetFirstClass}">Set first class</RadioButton>
            <RadioButton Command="{Binding SetSecondClass}">Set second class</RadioButton>
            <RadioButton Command="{Binding SetNull}" IsChecked="True">Set null</RadioButton>
        </StackPanel>
  
        <ContentControl Grid.Column="1" DataContext="{Binding SelectedClass}" Content="{Binding}">
            <ContentControl.Resources>
                <DataTemplate DataType="{x:Type PropertyGridTester:FirstClass}">
                    <telerik:RadPropertyGrid Item="{Binding}" AutoGeneratePropertyDefinitions="False" HorizontalAlignment="Stretch" SearchBoxVisibility="Collapsed"
                        SortAndGroupButtonsVisibility="Collapsed" DescriptionPanelVisibility="Collapsed" HorizontalContentAlignment="Stretch" LabelColumnWidth="110">
                        <telerik:RadPropertyGrid.PropertyDefinitions>
                            <telerik:PropertyDefinition Binding="{Binding Visible}" DisplayName="First class visible">
                                <telerik:PropertyDefinition.EditorTemplate>
                                    <DataTemplate>
                                        <TextBox Text="{Binding Visible}" />
                                    </DataTemplate>
                                </telerik:PropertyDefinition.EditorTemplate>
                            </telerik:PropertyDefinition>
                        </telerik:RadPropertyGrid.PropertyDefinitions>
                    </telerik:RadPropertyGrid>
                </DataTemplate>
                <DataTemplate DataType="{x:Type PropertyGridTester:SecondClass}">
                    <telerik:RadPropertyGrid Item="{Binding}" AutoGeneratePropertyDefinitions="False" HorizontalAlignment="Stretch" SearchBoxVisibility="Collapsed"
                        SortAndGroupButtonsVisibility="Collapsed" DescriptionPanelVisibility="Collapsed" HorizontalContentAlignment="Stretch" LabelColumnWidth="110">
                        <telerik:RadPropertyGrid.PropertyDefinitions>
                            <telerik:PropertyDefinition Binding="{Binding Visible}" DisplayName="Second class visible">
                                <telerik:PropertyDefinition.EditorTemplate>
                                    <DataTemplate>
                                        <TextBox Text="{Binding Visible}" />
                                    </DataTemplate>
                                </telerik:PropertyDefinition.EditorTemplate>
                            </telerik:PropertyDefinition>
                        </telerik:RadPropertyGrid.PropertyDefinitions>
                    </telerik:RadPropertyGrid>
                </DataTemplate>
            </ContentControl.Resources>
        </ContentControl>
  
    </Grid>
</Window>

using System;
using System.Windows.Input;
using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.ViewModel;
  
namespace PropertyGridTester
{
    public abstract class BaseClass : NotificationObject
    {
        private string _Visible = String.Empty;
  
        public string Visible
        {
            get { return _Visible; }
            set
            {
                if (_Visible == value)
                    return;
                _Visible = value;
                RaisePropertyChanged(() => Visible);
            }
        }
  
        private string _NotVisible = String.Empty;
  
        public string NotVisible
        {
            get { return _NotVisible; }
            set
            {
                if (_NotVisible == value)
                    return;
                _NotVisible = value;
                RaisePropertyChanged(() => NotVisible);
            }
        }
  
    }
  
    public class FirstClass : BaseClass
    {
    }
  
    public class SecondClass : BaseClass
    {
    }
  
    public class MainWindowViewModel : NotificationObject
    {
        public MainWindowViewModel()
        {
            SetFirstClass = new DelegateCommand(() => SelectedClass = new FirstClass());
            SetSecondClass = new DelegateCommand(() => SelectedClass = new SecondClass());
            SetNull = new DelegateCommand(() => SelectedClass = null);
        }
  
        public ICommand SetFirstClass { get; private set; }
  
        public ICommand SetSecondClass { get; private set; }
  
        public ICommand SetNull { get; private set; }
  
        private BaseClass _SelectedClass = null;
  
        public BaseClass SelectedClass
        {
            get { return _SelectedClass; }
            set
            {
                if (_SelectedClass == value)
                    return;
                _SelectedClass = value;
                RaisePropertyChanged(() => SelectedClass);
            }
        }
    }
}

4 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 27 Apr 2012, 12:57 PM
Hello,

We have had a similar issue with RadPropertyGrid placed in a DataTemplate with some older versions. Would you please confirm which version of RadControls you are currently using?

All the best,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Maxim
Top achievements
Rank 1
answered on 27 Apr 2012, 01:14 PM
2011.3.1116.40
0
Accepted
Ivan Ivanov
Telerik team
answered on 27 Apr 2012, 02:03 PM
Hello,

This issue should be fixed with Q1 2012. Would you please try it and confirm whether it works on your side?

Regards,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Maxim
Top achievements
Rank 1
answered on 28 Apr 2012, 01:03 PM
Yes, 2012 version work fine.
Tags
PropertyGrid
Asked by
Maxim
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Maxim
Top achievements
Rank 1
Share this question
or