@ -35,17 +35,6 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#endregion //AdvancedOptionsMenu
#region CustomTypeEditors
public static readonly DependencyProperty CustomTypeEditorsProperty = DependencyProperty . Register ( "CustomTypeEditors" , typeof ( CustomTypeEditorCollection ) , typeof ( PropertyGrid ) , new UIPropertyMetadata ( new CustomTypeEditorCollection ( ) ) ) ;
public CustomTypeEditorCollection CustomTypeEditors
{
get { return ( CustomTypeEditorCollection ) GetValue ( CustomTypeEditorsProperty ) ; }
set { SetValue ( CustomTypeEditorsProperty , value ) ; }
}
#endregion //CustomTypeEditors
#region DisplaySummary
public static readonly DependencyProperty DisplaySummaryProperty = DependencyProperty . Register ( "DisplaySummary" , typeof ( bool ) , typeof ( PropertyGrid ) , new UIPropertyMetadata ( true ) ) ;
@ -57,6 +46,17 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#endregion //DisplaySummary
#region EditorDefinitions
public static readonly DependencyProperty EditorDefinitionsProperty = DependencyProperty . Register ( "EditorDefinitions" , typeof ( EditorDefinitionCollection ) , typeof ( PropertyGrid ) , new UIPropertyMetadata ( new EditorDefinitionCollection ( ) ) ) ;
public EditorDefinitionCollection EditorDefinitions
{
get { return ( EditorDefinitionCollection ) GetValue ( EditorDefinitionsProperty ) ; }
set { SetValue ( EditorDefinitionsProperty , value ) ; }
}
#endregion //EditorDefinitions
#region Filter
public static readonly DependencyProperty FilterProperty = DependencyProperty . Register ( "Filter" , typeof ( string ) , typeof ( PropertyGrid ) , new UIPropertyMetadata ( null , OnFilterChanged ) ) ;
@ -117,10 +117,10 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#region Properties
public static readonly DependencyProperty PropertiesProperty = DependencyProperty . Register ( "Properties" , typeof ( PropertyCollection ) , typeof ( PropertyGrid ) , new UIPropertyMetadata ( null ) ) ;
public PropertyCollection Properties
public static readonly DependencyProperty PropertiesProperty = DependencyProperty . Register ( "Properties" , typeof ( PropertyItem Collection ) , typeof ( PropertyGrid ) , new UIPropertyMetadata ( null ) ) ;
public PropertyItem Collection Properties
{
get { return ( PropertyCollection ) GetValue ( PropertiesProperty ) ; }
get { return ( PropertyItem Collection ) GetValue ( PropertiesProperty ) ; }
private set { SetValue ( PropertiesProperty , value ) ; }
}
@ -406,77 +406,14 @@ namespace Microsoft.Windows.Controls.PropertyGrid
} ;
propertyItem . SetBinding ( PropertyItem . ValueProperty , binding ) ;
ITypeEditor editor = GetTypeEditor ( propertyItem ) ;
propertyItem . Editor = editor . ResolveEditor ( propertyItem ) ;
propertyItem . Editor = GetTypeEditor ( propertyItem ) ;
return propertyItem ;
}
private static PropertyCollection GetCategorizedProperties ( List < PropertyItem > propertyItems )
{
PropertyCollection propertyCollection = new PropertyCollection ( propertyItems ) ;
propertyCollection . GroupBy ( "Category" ) ;
propertyCollection . SortBy ( "Category" , ListSortDirection . Ascending ) ;
propertyCollection . SortBy ( "Name" , ListSortDirection . Ascending ) ;
return propertyCollection ;
}
private static PropertyCollection GetAlphabetizedProperties ( List < PropertyItem > propertyItems )
{
PropertyCollection propertyCollection = new PropertyCollection ( propertyItems ) ;
propertyCollection . SortBy ( "Name" , ListSortDirection . Ascending ) ;
return propertyCollection ;
}
private void SetSelectedObjectNameBinding ( object selectedObject )
{
if ( selectedObject is FrameworkElement )
{
var binding = new Binding ( "Name" ) ;
binding . Source = selectedObject ;
binding . Mode = BindingMode . OneWay ;
BindingOperations . SetBinding ( this , PropertyGrid . SelectedObjectNameProperty , binding ) ;
}
}
private void SetDragThumbMargin ( bool isCategorized )
{
if ( _d ragThumb = = null )
return ;
if ( isCategorized )
_d ragThumb . Margin = new Thickness ( 6 , 0 , 0 , 0 ) ;
else
_d ragThumb . Margin = new Thickness ( - 1 , 0 , 0 , 0 ) ;
}
private void ResetPropertyGrid ( )
{
SelectedObjectName = String . Empty ;
SelectedObjectType = null ;
_ propertyItemsCache = null ;
Properties = null ;
}
/// <summary>
/// Updates all property values in the PropertyGrid with the data from the SelectedObject
/// </summary>
public void Update ( )
private FrameworkElement GetTypeEditor ( PropertyItem propertyItem )
{
foreach ( var item in Properties )
{
BindingOperations . GetBindingExpressionBase ( item , PropertyItem . ValueProperty ) . UpdateTarget ( ) ;
}
}
#endregion //Methods
private ITypeEditor GetTypeEditor ( PropertyItem propertyItem )
{
ITypeEditor editor = null ;
editor = CreateCustomEditor ( propertyItem , CustomTypeEditors ) ;
FrameworkElement editor = GetCustomEditor ( propertyItem , EditorDefinitions ) ;
if ( editor = = null )
editor = CreateDefaultEditor ( propertyItem ) ;
@ -484,15 +421,15 @@ namespace Microsoft.Windows.Controls.PropertyGrid
return editor ;
}
private ITypeEditor Create CustomEditor( PropertyItem propertyItem , CustomType EditorCollection customTypeEditors )
private FrameworkElement Get CustomEditor( PropertyItem propertyItem , EditorDefinition Collection customTypeEditors )
{
ITypeEditor editor = null ;
FrameworkElement editor = null ;
//check for custom editor
if ( customTypeEditors . Count > 0 )
{
//first check if the custom editor is type based
ICustomType Editor customEditor = customTypeEditors [ propertyItem . PropertyType ] ;
IEditorDefinition customEditor = customTypeEditors [ propertyItem . PropertyType ] ;
if ( customEditor = = null )
{
//must be property based
@ -500,13 +437,16 @@ namespace Microsoft.Windows.Controls.PropertyGrid
}
if ( customEditor ! = null )
editor = customEditor . Editor ;
{
if ( customEditor . EditorTemplate ! = null )
editor = customEditor . EditorTemplate . LoadContent ( ) as FrameworkElement ;
}
}
return editor ;
}
private ITypeEditor CreateDefaultEditor ( PropertyItem propertyItem )
private FrameworkElement CreateDefaultEditor ( PropertyItem propertyItem )
{
ITypeEditor editor = null ;
@ -544,7 +484,66 @@ namespace Microsoft.Windows.Controls.PropertyGrid
else
editor = new TextBoxEditor ( ) ;
return editor ;
return editor . ResolveEditor ( propertyItem ) ;
}
private static PropertyItemCollection GetCategorizedProperties ( List < PropertyItem > propertyItems )
{
PropertyItemCollection propertyCollection = new PropertyItemCollection ( propertyItems ) ;
propertyCollection . GroupBy ( "Category" ) ;
propertyCollection . SortBy ( "Category" , ListSortDirection . Ascending ) ;
propertyCollection . SortBy ( "Name" , ListSortDirection . Ascending ) ;
return propertyCollection ;
}
private static PropertyItemCollection GetAlphabetizedProperties ( List < PropertyItem > propertyItems )
{
PropertyItemCollection propertyCollection = new PropertyItemCollection ( propertyItems ) ;
propertyCollection . SortBy ( "Name" , ListSortDirection . Ascending ) ;
return propertyCollection ;
}
private void SetSelectedObjectNameBinding ( object selectedObject )
{
if ( selectedObject is FrameworkElement )
{
var binding = new Binding ( "Name" ) ;
binding . Source = selectedObject ;
binding . Mode = BindingMode . OneWay ;
BindingOperations . SetBinding ( this , PropertyGrid . SelectedObjectNameProperty , binding ) ;
}
}
private void SetDragThumbMargin ( bool isCategorized )
{
if ( _d ragThumb = = null )
return ;
if ( isCategorized )
_d ragThumb . Margin = new Thickness ( 6 , 0 , 0 , 0 ) ;
else
_d ragThumb . Margin = new Thickness ( - 1 , 0 , 0 , 0 ) ;
}
private void ResetPropertyGrid ( )
{
SelectedObjectName = String . Empty ;
SelectedObjectType = null ;
_ propertyItemsCache = null ;
Properties = null ;
}
/// <summary>
/// Updates all property values in the PropertyGrid with the data from the SelectedObject
/// </summary>
public void Update ( )
{
foreach ( var item in Properties )
{
BindingOperations . GetBindingExpressionBase ( item , PropertyItem . ValueProperty ) . UpdateTarget ( ) ;
}
}
#endregion //Methods
}
}