Browse Source

PropertyGrid: finished CollectionEditor control. This editor will only work for collections that implement the IList interface.

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
8aaac023af
  1. 21
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/HomeView.xaml.cs
  2. 4
      ExtendedWPFToolkitSolution/Src/Samples/Samples/App.xaml.cs
  3. BIN
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CollectionEditors/Images/Delete16.png
  4. 193
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CollectionEditors/Implementation/CollectionEditor.cs
  5. 24
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CollectionEditors/Implementation/CollectionEditorDialog.xaml
  6. 55
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CollectionEditors/Implementation/CollectionEditorDialog.xaml.cs
  7. 90
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CollectionEditors/Themes/Generic.xaml
  8. 17
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Converters/ObjectTypeToNameConverter.cs
  9. 2
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditor.xaml
  10. 8
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditor.xaml.cs
  11. 81
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditorDialog.xaml
  12. 16
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs
  13. 1
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml
  14. 13
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

21
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/HomeView.xaml.cs

@ -39,6 +39,16 @@ namespace Samples.Modules.PropertyGrid.Views
}
}
private List<int> _valueTypes = new List<int>() { 1, 2, 3 };
public List<int> ValueTypes
{
get { return _valueTypes; }
set
{
_valueTypes = value;
}
}
private string _name;
public string Name
{
@ -69,6 +79,17 @@ namespace Samples.Modules.PropertyGrid.Views
}
}
private Color _color;
public Color Color
{
get { return _color; }
set
{
_color = value;
}
}
public Data()
{
Pages.Add(new Person() { FirstName = "One" });

4
ExtendedWPFToolkitSolution/Src/Samples/Samples/App.xaml.cs

@ -18,9 +18,9 @@ namespace Samples
{
// Put the following code before InitializeComponent()
// Sets the culture to French (France)
Thread.CurrentThread.CurrentCulture = new CultureInfo("da-DK");
//Thread.CurrentThread.CurrentCulture = new CultureInfo("da-DK");
// Sets the UI culture to French (France)
Thread.CurrentThread.CurrentUICulture = new CultureInfo("da-DK");
//Thread.CurrentThread.CurrentUICulture = new CultureInfo("da-DK");
base.OnStartup(e);
Bootstrapper bootstrapper = new Bootstrapper();

BIN
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CollectionEditors/Images/Delete16.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 682 B

193
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditorDialog.xaml.cs → ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CollectionEditors/Implementation/CollectionEditor.cs

@ -1,72 +1,75 @@
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;
using System.Collections.ObjectModel;
using System.Collections;
using System.Reflection;
using System.ComponentModel;
namespace Microsoft.Windows.Controls.PropertyGrid.Editors
namespace Microsoft.Windows.Controls
{
/// <summary>
/// Interaction logic for CollectionEditorDialog.xaml
/// </summary>
public partial class CollectionEditorDialog : Window
public class CollectionEditor : Control
{
#region Properties
public static readonly DependencyProperty ItemsProperty = DependencyProperty.Register("Items", typeof(ObservableCollection<object>), typeof(CollectionEditorDialog), new UIPropertyMetadata(null));
public static readonly DependencyProperty ItemsProperty = DependencyProperty.Register("Items", typeof(ObservableCollection<object>), typeof(CollectionEditor), new UIPropertyMetadata(null));
public ObservableCollection<object> Items
{
get { return (ObservableCollection<object>)GetValue(ItemsProperty); }
set { SetValue(ItemsProperty, value); }
}
public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(CollectionEditorDialog), new UIPropertyMetadata(null, OnItemsSourceChanged));
public IEnumerable ItemsSource
public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(IList), typeof(CollectionEditor), new UIPropertyMetadata(null, OnItemsSourceChanged));
public IList ItemsSource
{
get { return (IEnumerable)GetValue(ItemsSourceProperty); }
get { return (IList)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}
private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
CollectionEditorDialog collectionEditor = (CollectionEditorDialog)d;
CollectionEditor collectionEditor = (CollectionEditor)d;
if (collectionEditor != null)
collectionEditor.OnItemSourceChanged((IEnumerable)e.OldValue, (IEnumerable)e.NewValue);
collectionEditor.OnItemSourceChanged((IList)e.OldValue, (IList)e.NewValue);
}
public void OnItemSourceChanged(IEnumerable oldValue, IEnumerable newValue)
public void OnItemSourceChanged(IList oldValue, IList newValue)
{
if (newValue != null)
{
Items = new ObservableCollection<object>();
foreach (var item in newValue)
{
object clone = Activator.CreateInstance(item.GetType());
CopyValues(item, clone);
Items.Add(clone);
}
Items.Add(CreateClone(item));
}
}
public static readonly DependencyProperty NewItemTypesProperty = DependencyProperty.Register("NewItemTypes", typeof(IList), typeof(CollectionEditorDialog), new UIPropertyMetadata(null));
public static readonly DependencyProperty ItemsSourceTypeProperty = DependencyProperty.Register("ItemsSourceType", typeof(Type), typeof(CollectionEditor), new UIPropertyMetadata(null, new PropertyChangedCallback(ItemsSourceTypeChanged)));
public Type ItemsSourceType
{
get { return (Type)GetValue(ItemsSourceTypeProperty); }
set { SetValue(ItemsSourceTypeProperty, value); }
}
private static void ItemsSourceTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
CollectionEditor collectionEditor = (CollectionEditor)d;
if (collectionEditor != null)
collectionEditor.ItemsSourceTypeChanged((Type)e.OldValue, (Type)e.NewValue);
}
protected virtual void ItemsSourceTypeChanged(Type oldValue, Type newValue)
{
NewItemTypes = GetNewItemTypes(newValue);
}
public static readonly DependencyProperty NewItemTypesProperty = DependencyProperty.Register("NewItemTypes", typeof(IList), typeof(CollectionEditor), new UIPropertyMetadata(null));
public IList<Type> NewItemTypes
{
get { return (IList<Type>)GetValue(NewItemTypesProperty); }
set { SetValue(NewItemTypesProperty, value); }
}
public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register("SelectedItem", typeof(object), typeof(CollectionEditorDialog), new UIPropertyMetadata(null));
public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register("SelectedItem", typeof(object), typeof(CollectionEditor), new UIPropertyMetadata(null));
public object SelectedItem
{
get { return (object)GetValue(SelectedItemProperty); }
@ -77,61 +80,27 @@ namespace Microsoft.Windows.Controls.PropertyGrid.Editors
#region Constructors
private CollectionEditorDialog()
static CollectionEditor()
{
InitializeComponent();
DataContext = this;
DefaultStyleKeyProperty.OverrideMetadata(typeof(CollectionEditor), new FrameworkPropertyMetadata(typeof(CollectionEditor)));
}
public CollectionEditorDialog(Type type)
: this()
public CollectionEditor()
{
NewItemTypes = GetNewItemTypes(type);
Items = new ObservableCollection<object>();
CommandBindings.Add(new CommandBinding(ApplicationCommands.New, AddNew, CanAddNew));
CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, Delete, CanDelete));
CommandBindings.Add(new CommandBinding(ComponentCommands.MoveDown, MoveDown, CanMoveDown));
CommandBindings.Add(new CommandBinding(ComponentCommands.MoveUp, MoveUp, CanMoveUp));
}
#endregion //Constructors
private void OkButton_Click(object sender, RoutedEventArgs e)
{
PersistChanges();
Close();
}
private static void CopyValues(object source, object destination)
{
FieldInfo[] myObjectFields = source.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
foreach (FieldInfo fi in myObjectFields)
{
fi.SetValue(destination, fi.GetValue(source));
}
}
private static List<Type> GetNewItemTypes(Type type)
{
List<Type> types = new List<Type>();
var newItemTypes = type.GetGenericArguments();
foreach (var t in newItemTypes)
{
types.Add(t);
}
return types;
}
private void PersistChanges()
{
if (ItemsSource is IList)
{
IList list = (IList)ItemsSource;
//Need to copy all changes into ItemsSource
}
}
#region Commands
private void AddNew(object sender, ExecutedRoutedEventArgs e)
{
Type t = (Type)e.Parameter;
var newItem = Activator.CreateInstance(t);
var newItem = CreateNewItem((Type)e.Parameter);
Items.Add(newItem);
SelectedItem = newItem;
}
@ -139,7 +108,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid.Editors
private void CanAddNew(object sender, CanExecuteRoutedEventArgs e)
{
Type t = e.Parameter as Type;
if (t != null && t.IsClass)
if (t != null && t.GetConstructor(Type.EmptyTypes) != null)
e.CanExecute = true;
}
@ -184,5 +153,81 @@ namespace Microsoft.Windows.Controls.PropertyGrid.Editors
}
#endregion //Commands
#region Methods
private static void CopyValues(object source, object destination)
{
FieldInfo[] myObjectFields = source.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
foreach (FieldInfo fi in myObjectFields)
{
fi.SetValue(destination, fi.GetValue(source));
}
}
private object CreateClone(object source)
{
object clone = null;
Type type = source.GetType();
clone = Activator.CreateInstance(type);
CopyValues(source, clone);
return clone;
}
private IList CreateItemsSource()
{
IList list = null;
if (ItemsSourceType != null)
{
ConstructorInfo constructor = ItemsSourceType.GetConstructor(Type.EmptyTypes);
list = (IList)constructor.Invoke(null);
}
return list;
}
private object CreateNewItem(Type type)
{
return Activator.CreateInstance(type);
}
private static List<Type> GetNewItemTypes(Type type)
{
List<Type> types = new List<Type>();
var newItemTypes = type.GetGenericArguments();
foreach (var t in newItemTypes)
{
types.Add(t);
}
return types;
}
public void PersistChanges()
{
IList list = ResolveItemsSource();
if (list == null)
return;
//the easiest way to persist changes to the source is to just clear the source list and then add all items to it.
list.Clear();
foreach (var item in Items)
{
list.Add(item);
}
}
private IList ResolveItemsSource()
{
if (ItemsSource == null)
ItemsSource = CreateItemsSource();
return ItemsSource;
}
#endregion //Methods
}
}
}

24
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CollectionEditors/Implementation/CollectionEditorDialog.xaml

@ -0,0 +1,24 @@
<Window x:Class="Microsoft.Windows.Controls.CollectionEditorDialog"
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:propertyGrid="clr-namespace:Microsoft.Windows.Controls.PropertyGrid"
Title="Collection Editor" Height="400" Width="600" WindowStartupLocation="CenterScreen">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<extToolkit:CollectionEditor x:Name="_propertyGrid"
ItemsSourceType="{Binding ItemsSourceType, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}"
ItemsSource="{Binding ItemsSource, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}"/>
<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right" Margin="5" >
<Button Width="75" Margin="2" Click="OkButton_Click" IsDefault="True">OK</Button>
<Button Width="75" Margin="2" IsCancel="True">Cancel</Button>
</StackPanel>
</Grid>
</Window>

55
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CollectionEditors/Implementation/CollectionEditorDialog.xaml.cs

@ -0,0 +1,55 @@
using System;
using System.Windows;
using System.Collections;
namespace Microsoft.Windows.Controls
{
/// <summary>
/// Interaction logic for CollectionEditorDialog.xaml
/// </summary>
public partial class CollectionEditorDialog : Window
{
#region Properties
public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(IList), typeof(CollectionEditorDialog), new UIPropertyMetadata(null));
public IList ItemsSource
{
get { return (IList)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}
public static readonly DependencyProperty ItemsSourceTypeProperty = DependencyProperty.Register("ItemsSourceType", typeof(Type), typeof(CollectionEditorDialog), new UIPropertyMetadata(null));
public Type ItemsSourceType
{
get { return (Type)GetValue(ItemsSourceTypeProperty); }
set { SetValue(ItemsSourceTypeProperty, value); }
}
#endregion //Properties
#region Constructors
public CollectionEditorDialog()
{
InitializeComponent();
}
public CollectionEditorDialog(Type type)
: this()
{
ItemsSourceType = type;
}
#endregion //Constructors
#region Event Handlers
private void OkButton_Click(object sender, RoutedEventArgs e)
{
_propertyGrid.PersistChanges();
Close();
}
#endregion //Event Hanlders
}
}

90
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CollectionEditors/Themes/Generic.xaml

@ -0,0 +1,90 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Microsoft.Windows.Controls"
xmlns:coreConverters="clr-namespace:Microsoft.Windows.Controls.Core.Converters"
xmlns:propertyGrid="clr-namespace:Microsoft.Windows.Controls.PropertyGrid">
<coreConverters:ObjectTypeToNameConverter x:Key="ObjectTypeToNameConverter" />
<Style x:Key="CollectionEditorButtonStyle" TargetType="{x:Type Button}">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" Value="0.6" />
</Trigger>
</Style.Triggers>
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Height" Value="26" />
<Setter Property="Width" Value="26" />
</Style>
<Style TargetType="{x:Type local:CollectionEditor}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CollectionEditor}">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="1.5*" />
</Grid.ColumnDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Margin="0,0,0,5" Text="Select type:" />
<ComboBox x:Name="_newItemTypes" Grid.Row="1" Margin="0,0,0,3" HorizontalAlignment="Stretch"
ItemsSource="{Binding NewItemTypes, RelativeSource={RelativeSource TemplatedParent}}"
DisplayMemberPath="Name"
SelectedIndex="0"/>
<Button Margin="3,0,0,3" Grid.Row="1" Grid.Column="1" Padding="5,0" Content="Add"
Command="New" CommandParameter="{Binding SelectedItem, ElementName=_newItemTypes}" />
<ListBox x:Name="_itemsListBox" Grid.Row="2" Grid.ColumnSpan="2"
ItemsSource="{Binding Items, RelativeSource={RelativeSource TemplatedParent}}"
SelectedItem="{Binding SelectedItem, RelativeSource={RelativeSource TemplatedParent}}"
SelectedIndex="0">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource ObjectTypeToNameConverter}}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel Margin="7,2,0,0" VerticalAlignment="Top" Grid.Column="2" Grid.Row="2">
<Button Style="{StaticResource CollectionEditorButtonStyle}"
Command="ComponentCommands.MoveUp" CommandParameter="{Binding SelectedItem, ElementName=_itemsListBox}">
<Path Fill="#FF404040" Data="F0 M 6,0 L 12,7 8,7 8,12 4,12 4,7 0,7 Z" />
</Button>
<Button Margin="0,1,0,0" Style="{StaticResource CollectionEditorButtonStyle}"
Command="ComponentCommands.MoveDown" CommandParameter="{Binding SelectedItem, ElementName=_itemsListBox}">
<Path Fill="#FF404040" Data="F0 M 4,0 L 8,0 8,5 12,5 6,12 0,5 4,5 Z" />
</Button>
<Button Margin="0,7,0,0" Style="{StaticResource CollectionEditorButtonStyle}"
Command="Delete" CommandParameter="{Binding SelectedItem, ElementName=_itemsListBox}">
<Image Stretch="None" Height="16" Width="16" Margin="1" Source="/WPFToolkit.Extended;component/CollectionEditors/Images/Delete16.png" />
</Button>
</StackPanel>
</Grid>
<Grid Column="1" Margin="20,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Column="1" Text="Properties:" />
<propertyGrid:PropertyGrid Grid.Row="1" Grid.Column="1" Margin="0,5,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
SelectedObject="{Binding SelectedItem, RelativeSource={RelativeSource TemplatedParent}}"/>
</Grid>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

17
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Converters/ObjectTypeToNameConverter.cs

@ -0,0 +1,17 @@
using System;
using System.Windows.Data;
namespace Microsoft.Windows.Controls.Core.Converters
{
public class ObjectTypeToNameConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value.GetType().Name;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

2
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditor.xaml

@ -7,7 +7,7 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="(Collection)" VerticalAlignment="Center" />
<Button Grid.Column="1"
<Button x:Name="_editorButton" Grid.Column="1"
Content=" ... "
Click="Button_Click"/>
</Grid>

8
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditor.xaml.cs

@ -1,7 +1,6 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Collections;
using System.Windows.Data;
namespace Microsoft.Windows.Controls.PropertyGrid.Editors
@ -18,6 +17,12 @@ namespace Microsoft.Windows.Controls.PropertyGrid.Editors
InitializeComponent();
}
public CollectionEditor(bool isEditable) : this()
{
if (!isEditable)
_editorButton.Visibility = System.Windows.Visibility.Collapsed;
}
public void Attach(PropertyItem propertyItem)
{
_item = propertyItem;
@ -31,7 +36,6 @@ namespace Microsoft.Windows.Controls.PropertyGrid.Editors
private void Button_Click(object sender, RoutedEventArgs e)
{
CollectionEditorDialog editor = new CollectionEditorDialog(_item.PropertyType);
Binding binding = new Binding("Value");
binding.Source = _item;
binding.Mode = _item.IsWriteable ? BindingMode.TwoWay : BindingMode.OneWay;

81
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CollectionEditorDialog.xaml

@ -1,81 +0,0 @@
<Window x:Class="Microsoft.Windows.Controls.PropertyGrid.Editors.CollectionEditorDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:propertyGrid="clr-namespace:Microsoft.Windows.Controls.PropertyGrid"
Title="Collection Editor" Height="400" Width="600" WindowStartupLocation="CenterScreen">
<Window.CommandBindings>
<CommandBinding Command="New" Executed="AddNew" CanExecute="CanAddNew" />
<CommandBinding Command="Delete" Executed="Delete" CanExecute="CanDelete" />
<CommandBinding Command="ComponentCommands.MoveDown" Executed="MoveDown" CanExecute="CanMoveDown" />
<CommandBinding Command="ComponentCommands.MoveUp" Executed="MoveUp" CanExecute="CanMoveUp" />
</Window.CommandBindings>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Margin="0,0,10,0" MinWidth="200">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel>
<TextBlock Text="Select Type:" Margin="4" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ComboBox x:Name="_newItemTypes" Margin="0,0,4,0"
ItemsSource="{Binding NewItemTypes}"
DisplayMemberPath="Name"
SelectedIndex="0"/>
<Button Content="Add" Grid.Column="1" Width="50"
Command="New" CommandParameter="{Binding SelectedItem, ElementName=_newItemTypes}"/>
</Grid>
</StackPanel>
<ListBox x:Name="_listBox" Grid.Row="1" Margin="0,4,0,0"
ItemsSource="{Binding Items}"
SelectedIndex="0"
SelectedItem="{Binding SelectedItem}"/>
<StackPanel Grid.Column="1" Grid.Row="1" Margin="5,4,0,0">
<Button Command="ComponentCommands.MoveUp" CommandParameter="{Binding SelectedItem, ElementName=_listBox}">Up</Button>
<Button Command="ComponentCommands.MoveDown" CommandParameter="{Binding SelectedItem, ElementName=_listBox}">Down</Button>
<Button Command="Delete" CommandParameter="{Binding SelectedItem, ElementName=_listBox}" >Delete</Button>
</StackPanel>
</Grid>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Text="Properties:" Margin="4" />
<propertyGrid:PropertyGrid x:Name="_propertyGrid" Grid.Row="1" SelectedObject="{Binding SelectedItem}" />
</Grid>
</Grid>
<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right" Margin="5" >
<Button Width="75" Margin="2" Click="OkButton_Click" IsDefault="True">OK</Button>
<Button Width="75" Margin="2" IsCancel="True">Cancel</Button>
</StackPanel>
</Grid>
</Window>

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

@ -10,7 +10,6 @@ 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
{
@ -424,9 +423,18 @@ namespace Microsoft.Windows.Controls.PropertyGrid
editor = new FontComboBoxEditor();
else if (propertyItem.PropertyType.IsGenericType)
{
var interfaces = propertyItem.PropertyType.GetInterfaces();
if (interfaces.Contains(typeof(IEnumerable)))
editor = new CollectionEditor();
if (propertyItem.PropertyType.GetInterface("IList") != null)
{
bool isEditable = false;
var t = propertyItem.PropertyType.GetGenericArguments()[0];
if (!t.IsPrimitive && !t.Equals(typeof(String)))
isEditable = true;
editor = new Microsoft.Windows.Controls.PropertyGrid.Editors.CollectionEditor(isEditable);
}
else
editor = new TextBlockEditor();
}
else
editor = new TextBoxEditor();

1
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml

@ -10,6 +10,7 @@
<ResourceDictionary Source="/WPFToolkit.Extended;component/ChildWindow/Themes/Generic.xaml" />
<ResourceDictionary Source="/WPFToolkit.Extended;component/ColorCanvas/Themes/Generic.xaml" />
<ResourceDictionary Source="/WPFToolkit.Extended;component/ColorPicker/Themes/Generic.xaml" />
<ResourceDictionary Source="/WPFToolkit.Extended;component/CollectionEditors/Themes/Generic.xaml" />
<ResourceDictionary Source="/WPFToolkit.Extended;component/DropDownButton/Themes/Generic.xaml" />
<ResourceDictionary Source="/WPFToolkit.Extended;component/Magnifier/Themes/Generic.xaml" />
<ResourceDictionary Source="/WPFToolkit.Extended;component/MessageBox/Themes/Generic.xaml" />

13
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

@ -87,6 +87,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="CollectionEditors\Themes\Generic.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ColorCanvas\Themes\Generic.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@ -123,7 +127,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="PropertyGrid\Implementation\Editors\CollectionEditorDialog.xaml">
<Page Include="CollectionEditors\Implementation\CollectionEditorDialog.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
@ -177,6 +181,8 @@
<Compile Include="ButtonSpinner\Implementation\Spinner.cs" />
<Compile Include="ButtonSpinner\Implementation\ValidSpinDirections.cs" />
<Compile Include="Chromes\Implementation\ButtonChrome.cs" />
<Compile Include="CollectionEditors\Implementation\CollectionEditor.cs" />
<Compile Include="Core\Converters\ObjectTypeToNameConverter.cs" />
<Compile Include="ColorCanvas\Implementation\ColorCanvas.cs" />
<Compile Include="Core\Converters\CalculatorMemoryToVisibilityConverter.cs" />
<Compile Include="Core\Converters\TimeFormatToDateTimeFormatConverter.cs" />
@ -231,7 +237,7 @@
<Compile Include="PropertyGrid\Implementation\Editors\CollectionEditor.xaml.cs">
<DependentUpon>CollectionEditor.xaml</DependentUpon>
</Compile>
<Compile Include="PropertyGrid\Implementation\Editors\CollectionEditorDialog.xaml.cs">
<Compile Include="CollectionEditors\Implementation\CollectionEditorDialog.xaml.cs">
<DependentUpon>CollectionEditorDialog.xaml</DependentUpon>
</Compile>
<Compile Include="PropertyGrid\Implementation\Editors\ColorEditor.cs" />
@ -347,6 +353,9 @@
<ItemGroup>
<Resource Include="PropertyGrid\Images\ClearFilter16.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="CollectionEditors\Images\Delete16.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

Loading…
Cancel
Save