From dac6d6469ef4baf61e2b39151cc74dec70c36798 Mon Sep 17 00:00:00 2001 From: brianlagunas_cp Date: Thu, 28 Jul 2011 22:41:30 +0000 Subject: [PATCH] PropertyGrid: working on collection editor --- .../Editors/CollectionEditor.xaml | 14 ++++++ .../Editors/CollectionEditor.xaml.cs | 45 +++++++++++++++++ .../Editors/CollectionEditorDialog.xaml | 29 +++++++++++ .../Editors/CollectionEditorDialog.xaml.cs | 48 +++++++++++++++++++ .../Implementation/PropertyGrid.cs | 11 ++++- .../WPFToolkit.Extended.csproj | 14 ++++++ 6 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditor.xaml create mode 100644 ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditor.xaml.cs create mode 100644 ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditorDialog.xaml create mode 100644 ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditorDialog.xaml.cs diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditor.xaml b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditor.xaml new file mode 100644 index 00000000..6d39f0ea --- /dev/null +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditor.xaml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditorDialog.xaml.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditorDialog.xaml.cs new file mode 100644 index 00000000..17d92e2e --- /dev/null +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditorDialog.xaml.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; +using System.Collections; + +namespace Microsoft.Windows.Controls.PropertyGrid.Editors +{ + /// + /// Interaction logic for CollectionEditorDialog.xaml + /// + public partial class CollectionEditorDialog : Window + { + PropertyItem _item; + + public CollectionEditorDialog() + { + InitializeComponent(); + } + + public CollectionEditorDialog(PropertyItem item) + : this() + { + _item = item; + _listBox.ItemsSource = _item.Value as IEnumerable; + } + + //public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(object), typeof(CollectionEditorDialog), new UIPropertyMetadata(null)); + //public object ItemsSource + //{ + // get { return (object)GetValue(ItemsSourceProperty); } + // set { SetValue(ItemsSourceProperty, value); } + //} + + private void Button_Click(object sender, RoutedEventArgs e) + { + Close(); + } + } +} diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs index 2d2096e2..dafa69a2 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs @@ -10,6 +10,7 @@ using System.ComponentModel; using System.Windows.Input; using Microsoft.Windows.Controls.PropertyGrid.Editors; using Microsoft.Windows.Controls.PropertyGrid.Commands; +using System.Collections; namespace Microsoft.Windows.Controls.PropertyGrid { @@ -405,7 +406,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid { if (propertyItem.IsReadOnly) editor = new TextBlockEditor(); - else if (propertyItem.PropertyType == typeof(bool)) + else if (propertyItem.PropertyType == typeof(bool) || propertyItem.PropertyType == typeof(bool?)) editor = new CheckBoxEditor(); else if (propertyItem.PropertyType == typeof(decimal) || propertyItem.PropertyType == typeof(decimal?)) editor = new DecimalUpDownEditor(); @@ -413,7 +414,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid editor = new DoubleUpDownEditor(); else if (propertyItem.PropertyType == typeof(int) || propertyItem.PropertyType == typeof(int?)) editor = new IntegerUpDownEditor(); - else if (propertyItem.PropertyType == typeof(DateTime)) + else if (propertyItem.PropertyType == typeof(DateTime) || propertyItem.PropertyType == typeof(DateTime?)) editor = new DateTimeUpDownEditor(); else if ((propertyItem.PropertyType == typeof(Color))) editor = new ColorEditor(); @@ -421,6 +422,12 @@ namespace Microsoft.Windows.Controls.PropertyGrid editor = new EnumComboBoxEditor(); else if (propertyItem.PropertyType == typeof(FontFamily) || propertyItem.PropertyType == typeof(FontWeight) || propertyItem.PropertyType == typeof(FontStyle) || propertyItem.PropertyType == typeof(FontStretch)) editor = new FontComboBoxEditor(); + else if (propertyItem.PropertyType.IsGenericType) + { + var interfaces = propertyItem.PropertyType.GetInterfaces(); + if (interfaces.Contains(typeof(IEnumerable))) + editor = new CollectionEditor(); + } else editor = new TextBoxEditor(); } diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj index 34fdc425..31576e21 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj @@ -119,6 +119,14 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + Designer MSBuild:Compile @@ -215,6 +223,12 @@ + + CollectionEditor.xaml + + + CollectionEditorDialog.xaml +