add partial codes

This commit is contained in:
NaBian committed 2020-06-15 00:24:18 +08:00
1 parent 507a44aa25
commit aeb5d2a3b8
37 files changed
+806 -4

No files matched your search

@@ -0,0 +1,23 @@
using System.Windows;
using System.Windows.Controls.Primitives;
using HandyControl.Tools;
namespace HandyControl.Controls
{
public class BooleanPropertyEditor : PropertyEditorBase
{
public override FrameworkElement CreateElement(PropertyItem propertyItem)
{
var button = new ToggleButton
{
Style = ResourceHelper.GetResource<Style>("ToggleButtonSwitch"),
HorizontalAlignment = HorizontalAlignment.Left,
IsEnabled = !propertyItem.IsReadOnly
};
button.SetBinding(ToggleButton.IsCheckedProperty, CreateBinding(propertyItem));
return button;
}
}
}
@@ -0,0 +1,19 @@
using System.Windows;
namespace HandyControl.Controls
{
public class DateTimePropertyEditor : PropertyEditorBase
{
public override FrameworkElement CreateElement(PropertyItem propertyItem)
{
var picker = new DateTimePicker
{
IsEnabled = !propertyItem.IsReadOnly
};
picker.SetBinding(DateTimePicker.SelectedDateTimeProperty, CreateBinding(propertyItem));
return picker;
}
}
}
@@ -0,0 +1,31 @@
using System.Windows;
namespace HandyControl.Controls
{
public class IntegerPropertyEditor : PropertyEditorBase
{
public IntegerPropertyEditor(double minimum, double maximum)
{
Minimum = minimum;
Maximum = maximum;
}
public double Minimum { get; set; }
public double Maximum { get; set; }
public override FrameworkElement CreateElement(PropertyItem propertyItem)
{
var numericUpDown = new NumericUpDown
{
IsReadOnly = propertyItem.IsReadOnly,
Minimum = Minimum,
Maximum = Maximum
};
numericUpDown.SetBinding(NumericUpDown.ValueProperty, CreateBinding(propertyItem));
return numericUpDown;
}
}
}
@@ -0,0 +1,18 @@
using System.Windows;
using System.Windows.Data;
namespace HandyControl.Controls
{
public abstract class PropertyEditorBase : FrameworkElement
{
public abstract FrameworkElement CreateElement(PropertyItem propertyItem);
public virtual Binding CreateBinding(PropertyItem propertyItem) =>
new Binding(propertyItem.PropertyName)
{
Source = propertyItem.Value,
Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};
}
}
@@ -0,0 +1,19 @@
using System.Windows;
namespace HandyControl.Controls
{
public class StringPropertyEditor : PropertyEditorBase
{
public override FrameworkElement CreateElement(PropertyItem propertyItem)
{
var textbox = new System.Windows.Controls.TextBox
{
IsReadOnly = propertyItem.IsReadOnly
};
textbox.SetBinding(System.Windows.Controls.TextBox.TextProperty, CreateBinding(propertyItem));
return textbox;
}
}
}