6 changed files with 94 additions and 37 deletions
@ -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(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue