use PropertyDescriptor
This commit is contained in:
1 parent
f7a39f3d32
commit
c259b7943d
8 files changed
+71
-111
No files matched your search
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls.Primitives;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class EnumPropertyEditor : PropertyEditorBase
|
||||
{
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem)
|
||||
{
|
||||
var picker = new System.Windows.Controls.ComboBox
|
||||
{
|
||||
IsEnabled = !propertyItem.IsReadOnly,
|
||||
ItemsSource = Enum.GetValues(propertyItem.PropertyType)
|
||||
};
|
||||
|
||||
picker.SetBinding(Selector.SelectedValueProperty, CreateBinding(propertyItem));
|
||||
|
||||
return picker;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,12 +11,12 @@ namespace HandyControl.Controls
|
||||
new Binding(propertyItem.PropertyName)
|
||||
{
|
||||
Source = propertyItem.Value,
|
||||
Mode = GetBindingMode(),
|
||||
UpdateSourceTrigger = GetUpdateSourceTrigger()
|
||||
Mode = GetBindingMode(propertyItem),
|
||||
UpdateSourceTrigger = GetUpdateSourceTrigger(propertyItem)
|
||||
};
|
||||
|
||||
public virtual BindingMode GetBindingMode() => BindingMode.OneWay;
|
||||
public virtual BindingMode GetBindingMode(PropertyItem propertyItem) => propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
|
||||
|
||||
public virtual UpdateSourceTrigger GetUpdateSourceTrigger() => UpdateSourceTrigger.Default;
|
||||
public virtual UpdateSourceTrigger GetUpdateSourceTrigger(PropertyItem propertyItem) => UpdateSourceTrigger.PropertyChanged;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user