Browse Source
public class MyCustomEditor : ITypeEditor
{
public FrameworkElement ResolveEditor(PropertyItem propertyItem)
{
TextBox editor = new TextBox();
Binding binding = new Binding("Value"); //bind to the Value property of the PropertyItem instance
binding.Source = propertyItem;
binding.Mode = propertyItem.IsWriteable ? BindingMode.TwoWay : BindingMode.OneWay;
BindingOperations.SetBinding(editor, TextBox.TextProperty, binding);
return editor;
}
}
Then attribute the property to use the editor on:
private TimeSpan _timeSpan;
[TypeEditor(typeof(MyCustomEditor))]
public TimeSpan TimeSpan
{
get { return _timeSpan; }
set { _timeSpan = value; }
}
pull/1645/head
3 changed files with 30 additions and 4 deletions
@ -0,0 +1,18 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Microsoft.Windows.Controls.PropertyGrid.Attributes |
||||
|
{ |
||||
|
public class TypeEditorAttribute : Attribute |
||||
|
{ |
||||
|
public Type Type { get; set; } |
||||
|
|
||||
|
public TypeEditorAttribute(Type type) |
||||
|
{ |
||||
|
var valueSourceInterface = type.GetInterface("Microsoft.Windows.Controls.PropertyGrid.Editors.ITypeEditor"); |
||||
|
if (valueSourceInterface == null) |
||||
|
throw new ArgumentException("Type must implement the ITypeEditor interface.", "type"); |
||||
|
|
||||
|
Type = type; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue