Jelajahi Sumber

wpf: Fixed slight problem with option field controls that had an expression

Kenric Nugteren 1 bulan lalu
induk
melakukan
e12b8df868

+ 28 - 0
inabox.wpf/DigitalForms/Designer/Controls/Fields/DFOptionControl.cs

@@ -90,6 +90,16 @@ public class ButtonsOptionControl : Grid, IOptionControl
         OnChanged();
     }
 
+    private void DeselectButtons()
+    {
+        foreach (var child in Children)
+        {
+            if (child is OptionButton childButton)
+            {
+                childButton.Selected = false;
+            }
+        }
+    }
     private void SelectButton(OptionButton button)
     {
         foreach (var child in Children)
@@ -119,6 +129,7 @@ public class ButtonsOptionControl : Grid, IOptionControl
 
     public void SetValue(string value)
     {
+        var found = false;
         foreach (var child in Children)
         {
             if (child is OptionButton button)
@@ -126,9 +137,14 @@ public class ButtonsOptionControl : Grid, IOptionControl
                 if (button.Option == value)
                 {
                     SelectButton(button);
+                    found = true;
                 }
             }
         }
+        if (!found)
+        {
+            DeselectButtons();
+        }
     }
 
     public bool IsEmpty() => GetValue() == null;
@@ -182,6 +198,7 @@ public class RadioOptionControl : Grid, IOptionControl
 
     public void SetValue(string value)
     {
+        var found = false;
         foreach (var child in Children)
         {
             if (child is RadioButton radio)
@@ -189,6 +206,17 @@ public class RadioOptionControl : Grid, IOptionControl
                 if ((string)radio.Tag == value)
                 {
                     radio.IsChecked = true;
+                    found = true;
+                }
+            }
+        }
+        if (!found)
+        {
+            foreach (var child in Children)
+            {
+                if (child is RadioButton radio)
+                {
+                    radio.IsChecked = false;
                 }
             }
         }