| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using InABox.Core;
- using InABox.Mobile;
- namespace PRS.Mobile
- {
- class DigitalFormBoolean : MobileTabStrip, IDigitalFormField<DFLayoutBooleanField, DFLayoutBooleanFieldProperties, bool, bool?>
- {
- private bool _value;
-
- private DFLayoutBooleanField? _definition;
- public DFLayoutBooleanField? Definition
- {
- get => _definition;
- set
- {
- _definition = value;
- Initialize(value ?? new DFLayoutBooleanField());
- }
- }
-
- public bool Value
- {
- get => _value;
- set
- {
- _value = value;
- UpdateUI();
- }
- }
- private void UpdateUI()
- {
- SelectedItem = (Value ? Items[0] : Items[1]);
- }
- public bool IsEmpty => false;
- public void Deserialize(DFLoadStorageEntry entry)
- {
- Value = Definition?.Properties.DeserializeValue(entry) == true;
- UpdateUI();
- }
- public void Serialize(DFSaveStorageEntry entry)
- => entry.SetValue(Value);
-
- private bool _readOnly;
- public bool ReadOnly
- {
- get => _readOnly;
- set
- {
- _readOnly = value;
- UpdateStatus();
- }
- }
- public event DigitalFormViewChangedHandler? ValueChanged;
-
- public DigitalFormBoolean()
- {
- HeightRequest = 35;
- Items.Add(new MobileTabStripItem() { Text = "Yes"});
- Items.Add(new MobileTabStripItem() { Text = "No"});
-
-
- SelectionChanged += (sender, args) =>
- {
- Value = SelectedItem.Index == 0;
- ValueChanged?.Invoke(this,new DigitalFormViewChangedArgs(Definition,Value));
- };
- }
- private void Initialize(DFLayoutBooleanField value)
- {
- Items[0].Text = value.Properties.TrueValue;
- Items[1].Text = value.Properties.FalseValue;
- UpdateStatus();
- }
- private void UpdateStatus()
- {
- IsEnabled = !_readOnly && Definition?.Properties.Secure == false;
-
- var unselected = DigitalFormUtils.GetColors(!IsEnabled, Definition?.Properties.Required ?? false, true);
- BorderColor = unselected.Border;
- UnselectedBackground = unselected.Background;
- UnselectedForeground = unselected.Foreground;
-
- var selected = DigitalFormUtils.GetColors(!IsEnabled, false, false);
- SelectedBackground = selected.Background;
- SelectedForeground = selected.Foreground;
- }
-
-
- }
- }
|