- How does it know what properties an object have?
It uses System.ComponentModel.TypeDescriptor
to determine the properties that a type has via TypeDescriptor.GetProperties
. A PropertyDescriptor
provides a wealth of information about each property (e.g., PropertyDescriptor.IsReadOnly
will tell you that a property is readonly). Further, using PropertyDescriptor.GetValue
and PropertyDescriptor.SetValue
, the values of properties can be obtained and written to.
- How does it render the control to edit a Value?
- How does it decide what control to render? (i'm guessing meta data descriptions on the properties)
It uses a custom control called a PropertyGrid
which exposes an ObservableCollection
of Item
s. Item
is merely a base class for the core model object which is Property
. Property
exposes the underlying type (PropertyDescritor.PropertyType
) of the property and exposes the PropertyDescriptor.GetValue
and PropertyDescriptor.SetValue
methods via Property.Value
. This, in turn, is what is bound to to enable the editing. DataTemplate
s are the key here. A few CLR types have custom DataTemplate
s that render the controls you see. For example, the Boolean
type is rendered as a CheckBox
while an Enum
is rendered as a ComboBox
. The default DataTemplate
is a TextBox
.
- Where is the XAML or CodeBehind code that does all the magic?
The propensity of it is in Themes\Default.xaml
.
The code can be summarized as thus. There is data (Data\Property
) that encapsulates the information about properties of an object and provides a property (Property.Value
) to read and write the value of a property. This data is exposed as an ObservableCollection
in a custom control (PropertyGrid
) which is rendered using DataTemplate
s in Themes\Default.xaml
.
There is lots of XAML code in the Default.xaml file, but as far as I can tell it is only styles and the looks that are defined there.
Don't overlook the DataTemplate
s.