Browse Source

PropertyGrid: improved how I populated the property descriptors and starting to work on filtering

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
6a03a7bf8e
  1. 88
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs
  2. 8
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Themes/Generic.xaml

88
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs

@ -18,6 +18,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid
private Thumb _dragThumb;
private List<PropertyItem> _propertyItemsCache;
private CollectionViewSource _collectionViewSource;
#endregion //Members
@ -34,6 +35,40 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#endregion //CustomTypeEditors
#region DisplaySummary
public static readonly DependencyProperty DisplaySummaryProperty = DependencyProperty.Register("DisplaySummary", typeof(bool), typeof(PropertyGrid), new UIPropertyMetadata(true));
public bool DisplaySummary
{
get { return (bool)GetValue(DisplaySummaryProperty); }
set { SetValue(DisplaySummaryProperty, value); }
}
#endregion //DisplaySummary
#region Filter
public static readonly DependencyProperty FilterProperty = DependencyProperty.Register("Filter", typeof(string), typeof(PropertyGrid), new UIPropertyMetadata(null, OnFilterChanged));
public string Filter
{
get { return (string)GetValue(FilterProperty); }
set { SetValue(FilterProperty, value); }
}
private static void OnFilterChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
PropertyGrid propertyGrid = o as PropertyGrid;
if (propertyGrid != null)
propertyGrid.OnFilterChanged((string)e.OldValue, (string)e.NewValue);
}
protected virtual void OnFilterChanged(string oldValue, string newValue)
{
}
#endregion //Filter
#region IsCategorized
public static readonly DependencyProperty IsCategorizedProperty = DependencyProperty.Register("IsCategorized", typeof(bool), typeof(PropertyGrid), new UIPropertyMetadata(true, OnIsCategorizedChanged));
@ -200,17 +235,6 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#endregion //SelectedProperty
#region DisplaySummary
public static readonly DependencyProperty DisplaySummaryProperty = DependencyProperty.Register("DisplaySummary", typeof(bool), typeof(PropertyGrid), new UIPropertyMetadata(true));
public bool DisplaySummary
{
get { return (bool)GetValue(DisplaySummaryProperty); }
set { SetValue(DisplaySummaryProperty, value); }
}
#endregion //DisplaySummary
#endregion //Properties
#region Constructors
@ -220,6 +244,12 @@ namespace Microsoft.Windows.Controls.PropertyGrid
DefaultStyleKeyProperty.OverrideMetadata(typeof(PropertyGrid), new FrameworkPropertyMetadata(typeof(PropertyGrid)));
}
public PropertyGrid()
{
CollectionViewSource collectionView = new CollectionViewSource() { Source = Properties };
Resources.Add("PropertiesSource", collectionView);
}
#endregion //Constructors
#region Base Class Overrides
@ -275,23 +305,43 @@ namespace Microsoft.Windows.Controls.PropertyGrid
if (instance == null)
return propertyItems;
var properties = TypeDescriptor.GetProperties(instance.GetType(), new Attribute[] { new PropertyFilterAttribute(PropertyFilterOptions.All) });
try
{
// Get all properties of the type
propertyItems.AddRange(properties.Cast<PropertyDescriptor>().
Where(p => p.IsBrowsable && p.Name != "GenericParameterAttributes").
Select(property => CreatePropertyItem(property, instance, this)));
var descriptors = GetPropertyDescriptors(instance);
foreach (PropertyDescriptor descriptor in descriptors)
{
propertyItems.Add(CreatePropertyItem(descriptor, instance, this));
}
}
catch (Exception ex)
{
//TODO: handle this some how
}
return propertyItems;
}
private static PropertyDescriptorCollection GetPropertyDescriptors(object instance)
{
PropertyDescriptorCollection descriptors;
TypeConverter tc = TypeDescriptor.GetConverter(instance);
if (tc == null || !tc.GetPropertiesSupported())
{
if (instance is ICustomTypeDescriptor)
descriptors = ((ICustomTypeDescriptor)instance).GetProperties();
else
descriptors = TypeDescriptor.GetProperties(instance.GetType());
}
else
{
descriptors = tc.GetProperties(instance);
}
return descriptors;
}
private PropertyItem CreatePropertyItem(PropertyDescriptor property, object instance, PropertyGrid grid)
{
PropertyItem propertyItem = new PropertyItem(instance, property, grid);
@ -349,7 +399,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid
}
catch (Exception ex)
{
//TODO: handle this some how
}
editor.Attach(propertyItem);

8
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Themes/Generic.xaml

@ -1,5 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:extToolkit="clr-namespace:Microsoft.Windows.Controls"
xmlns:local="clr-namespace:Microsoft.Windows.Controls.PropertyGrid"
xmlns:converters="clr-namespace:Microsoft.Windows.Controls.Core.Converters"
xmlns:pgConverters="clr-namespace:Microsoft.Windows.Controls.PropertyGrid.Converters"
@ -326,17 +327,20 @@
</RadioButton>
</StackPanel>
</Grid>
<TextBox Grid.Column="1" Text="Not Implemented" Margin="4" Opacity=".5" Visibility="Hidden" />
<extToolkit:WatermarkTextBox Grid.Column="1" Margin="4" Opacity=".5"
Text="{Binding Filter, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}"
Watermark="Search" />
</Grid>
<Grid Grid.Row="2" Background="White">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding Properties, RelativeSource={RelativeSource TemplatedParent}}" IsTabStop="False" Focusable="False" >
<!--<ItemsControl ItemsSource="{Binding Source={StaticResource PropertiesSource}}" IsTabStop="False" Focusable="False" >-->
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>

Loading…
Cancel
Save