Why PropertyGrid generate excess properties, when AutoGeneratePropertyDefinitions is set to false?
<
Window
x:Class
=
"PropertyGridTester.MainWindow"
xmlns:PropertyGridTester
=
"clr-namespace:PropertyGridTester"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
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);
}
}
}
}