Browse Source

PropertyGrid: added feature that allows you to specify a display name when using the IItemsSource attribute.

pull/1645/head
brianlagunas_cp 14 years ago
parent
commit
f3a0d20ebd
  1. 32
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/CustomItemsSource.xaml.cs
  2. 28
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Attributes/IItemsSource.cs
  3. 43
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/ItemsSourceAttributeEditor.cs
  4. 24
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/ItemsSourceEditor.cs
  5. 2
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGridUtilities.cs
  6. 2
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

32
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.PropertyGrid/Views/CustomItemsSource.xaml.cs

@ -1,11 +1,10 @@
using Samples.Infrastructure.Controls;
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System;
using System.Windows.Media;
using System.Windows;
using Microsoft.Windows.Controls.PropertyGrid.Attributes;
using System.Windows.Media;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Windows.Controls.PropertyGrid.Attributes;
using Samples.Infrastructure.Controls;
namespace Samples.Modules.PropertyGrid.Views
{
@ -70,12 +69,25 @@ namespace Samples.Modules.PropertyGrid.Views
public class FontSizeItemsSource : IItemsSource
{
public IList<object> GetValues()
public ItemCollection GetValues()
{
List<object> sizes = new List<object>()
{
5.0,5.5,6.0,6.5,7.0,7.5,8.0,8.5,9.0,9.5,10.0,12.0,14.0,16.0,18.0,20.0
};
ItemCollection sizes = new ItemCollection();
sizes.Add(5.0, "Five");
sizes.Add(5.5);
sizes.Add(6.0, "Six");
sizes.Add(6.5);
sizes.Add(7.0, "Seven");
sizes.Add(7.5);
sizes.Add(8.0, "Eight");
sizes.Add(8.5);
sizes.Add(9.0, "Nine");
sizes.Add(9.5);
sizes.Add(10.0);
sizes.Add(12.0, "Twelve");
sizes.Add(14.0);
sizes.Add(16.0);
sizes.Add(18.0);
sizes.Add(20.0);
return sizes;
}
}

28
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Attributes/IItemsSource.cs

@ -5,6 +5,32 @@ namespace Microsoft.Windows.Controls.PropertyGrid.Attributes
{
public interface IItemsSource
{
IList<object> GetValues();
ItemCollection GetValues();
}
public class Item
{
public string DisplayName { get; set; }
public object Value { get; set; }
}
public class ItemCollection : List<Item>
{
public void Add(object value)
{
Item item = new Item();
item.DisplayName = value.ToString();
item.Value = value;
base.Add(item);
}
public void Add(object value, string displayName)
{
Item newItem = new Item();
newItem.DisplayName = displayName;
newItem.Value = value;
base.Add(newItem);
}
}
}

43
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/ItemsSourceAttributeEditor.cs

@ -0,0 +1,43 @@
using System;
using Microsoft.Windows.Controls.PropertyGrid.Attributes;
namespace Microsoft.Windows.Controls.PropertyGrid.Editors
{
public class ItemsSourceAttributeEditor : TypeEditor<System.Windows.Controls.ComboBox>
{
private readonly ItemsSourceAttribute _attribute;
public ItemsSourceAttributeEditor(ItemsSourceAttribute attribute)
{
_attribute = attribute;
}
protected override void SetValueDependencyProperty()
{
ValueProperty = System.Windows.Controls.ComboBox.SelectedValueProperty;
}
protected override void ResolveValueBinding(PropertyItem propertyItem)
{
SetItemsSource();
base.ResolveValueBinding(propertyItem);
}
protected override void SetControlProperties()
{
Editor.DisplayMemberPath = "DisplayName";
Editor.SelectedValuePath = "Value";
}
private void SetItemsSource()
{
Editor.ItemsSource = CreateItemsSource();
}
private System.Collections.IEnumerable CreateItemsSource()
{
var instance = Activator.CreateInstance(_attribute.Type);
return (instance as IItemsSource).GetValues();
}
}
}

24
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/ItemsSourceEditor.cs

@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Windows.Controls.PropertyGrid.Attributes;
namespace Microsoft.Windows.Controls.PropertyGrid.Editors
{
public class ItemsSourceEditor : ComboBoxEditor
{
private ItemsSourceAttribute _attribute;
public ItemsSourceEditor(ItemsSourceAttribute attribute)
{
_attribute = attribute;
}
protected override IList<object> CreateItemsSource(PropertyItem propertyItem)
{
var instance = Activator.CreateInstance(_attribute.Type);
return (instance as IItemsSource).GetValues();
}
}
}

2
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGridUtilities.cs

@ -106,7 +106,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid
var itemsSourceAttribute = GetAttribute<ItemsSourceAttribute>(propertyItem.PropertyDescriptor);
if (itemsSourceAttribute != null)
editor = new ItemsSourceEditor(itemsSourceAttribute).ResolveEditor(propertyItem);
editor = new ItemsSourceAttributeEditor(itemsSourceAttribute).ResolveEditor(propertyItem);
var editorAttribute = GetAttribute<EditorAttribute>(propertyItem.PropertyDescriptor);
if (editorAttribute != null)

2
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

@ -293,7 +293,7 @@
<Compile Include="PropertyGrid\Implementation\Editors\DoubleUpDownEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\EnumComboBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\FontComboBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\ItemsSourceEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\ItemsSourceAttributeEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\TimeSpanEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\IntegerUpDownEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\ITypeEditor.cs" />

Loading…
Cancel
Save