-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathPropertyEditorBase.cs
More file actions
35 lines (28 loc) · 1.51 KB
/
PropertyEditorBase.cs
File metadata and controls
35 lines (28 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Reflection;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using HandyControl.Controls;
namespace HandyControl.Controls
{
public abstract class PropertyEditorBase : DependencyObject
{
public abstract FrameworkElement CreateElement(PropertyItem propertyItem);
public virtual void CreateBinding(PropertyItem propertyItem, DependencyObject element)
{
BindingOperations.SetBinding(element, GetDependencyProperty(),
new Binding($"{propertyItem.PropertyName}")
{
Source = propertyItem.Value,
Mode = GetBindingMode(propertyItem),
UpdateSourceTrigger = GetUpdateSourceTrigger(propertyItem),
Converter = GetConverter(propertyItem)
});
}
public abstract DependencyProperty GetDependencyProperty();
public virtual BindingMode GetBindingMode(PropertyItem propertyItem) => propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
public virtual UpdateSourceTrigger GetUpdateSourceTrigger(PropertyItem propertyItem) => UpdateSourceTrigger.PropertyChanged;
protected virtual IValueConverter GetConverter(PropertyItem propertyItem) => null;
}
}