| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using InABox.Core;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- namespace InABox.DynamicGrid;
- public class DFBooleanControl : DynamicFormFieldControl<DFLayoutBooleanField, DFLayoutBooleanFieldProperties, bool?, bool?>
- {
- private IOptionControl OptionControl = null!; // Late-initialised
- protected override FrameworkElement Create()
- {
- var options = new[] { Field.Properties.TrueValue, Field.Properties.FalseValue };
- var defValue = Field.Properties.Default switch
- {
- true => Field.Properties.TrueValue,
- false => Field.Properties.FalseValue,
- null => null
- };
- return Field.Properties.Type switch
- {
- DesignBooleanFieldType.Buttons => SetControl(new ButtonsOptionControl(options, ChangeField, defValue)),
- DesignBooleanFieldType.ComboBox => SetControl(new ComboBoxOptionControl(options, ChangeField, defValue)),
- DesignBooleanFieldType.Checkbox or _ => SetControl(new CheckBoxOptionControl(Field.Properties.TrueValue, Field.Properties.FalseValue, ChangeField, Field.Properties.Required, Field.Properties.Default)),
- };
- }
- private T SetControl<T>(T value)
- where T : FrameworkElement, IOptionControl
- {
- OptionControl = value;
- return value;
- }
- public override bool? GetSerializedValue()
- {
- return GetValue();
- }
- public override void SetSerializedValue(bool? value)
- {
- SetValue(value);
- }
- public override bool? GetValue()
- {
- var val = OptionControl.GetValue();
- if(val == Field.Properties.TrueValue)
- {
- return true;
- }
- else if(val == Field.Properties.FalseValue)
- {
- return false;
- }
- else
- {
- return null;
- }
- }
- public override void SetValue(bool? value) => OptionControl.SetValue(value switch
- {
- true => Field.Properties.TrueValue,
- false => Field.Properties.FalseValue,
- null => null
- });
- protected override bool IsEmpty() => OptionControl.IsEmpty();
- }
|