Ignoring AutoGeneratePropertyDefinitions

5 posts, 1 answers
  1. Maxim
    Maxim avatar
    12 posts
    Member since:
    Mar 2012

    Posted 27 Apr 2012 Link to this post

    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);
                }
            }
        }
    }

  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 27 Apr 2012 Link to this post

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

    Posted 27 Apr 2012 Link to this post

    2011.3.1116.40
  5. Answer
    Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 27 Apr 2012 Link to this post

    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 >>
  6. Maxim
    Maxim avatar
    12 posts
    Member since:
    Mar 2012

    Posted 28 Apr 2012 Link to this post

    Yes, 2012 version work fine.
Back to Top
UI for WPF is Visual Studio 2017 Ready