Browse Source

avalonia: Converted DFOptionFieldControl into ButtonStrip, rather than TabStrip

Kenric Nugteren 1 month ago
parent
commit
e1f403ebec

+ 20 - 15
PRS.Avalonia/PRS.Avalonia/Components/FormsEditor/Fields/DFOptionFieldControl.cs

@@ -4,6 +4,7 @@ using Avalonia.Controls.Primitives;
 using Avalonia.Data;
 using Avalonia.Layout;
 using Avalonia.Media;
+using InABox.Avalonia.Components;
 using InABox.Core;
 using System;
 using System.Collections.Generic;
@@ -26,51 +27,55 @@ public class ButtonsOptionControl : ContentControl, IOptionControl
 {
     private readonly Action OnChanged;
 
-    private TabStrip _tabStrip;
+    private ButtonStrip _strip;
 
     IBrush? IOptionControl.Background
     {
-        get => _tabStrip.Background;
-        set => _tabStrip.Background = value;
+        get => _strip.Background;
+        set => _strip.Background = value;
     }
 
     public ButtonsOptionControl(string[] options, Action onChanged)
     {
         OnChanged = onChanged;
 
-        _tabStrip = new TabStrip();
-        _tabStrip.Classes.Add("ButtonsList");
-        _tabStrip.Classes.Add("Standard");
+        _strip = new ButtonStrip();
+        _strip.Classes.Add("TabStrip");
+
+        // _tabStrip = new TabStrip();
+        // _tabStrip.Classes.Add("ButtonsList");
+        // _tabStrip.Classes.Add("Standard");
 
         foreach (var option in options)
         {
-            var item = new TabStripItem
+            var item = new ButtonStripItem
             {
-                Content = option.Replace("\r", "").Replace("\n", ""),
+                Text = option.Replace("\r", "").Replace("\n", ""),
                 Tag = option
             };
-            _tabStrip.Items.Add(item);
+            _strip.Items.Add(item);
         }
-        _tabStrip.SelectedValueBinding = new Binding("Tag");
 
-        _tabStrip.SelectionChanged += ButtonsOptionControl_SelectionChanged;
+        _strip.SelectedIndex = -1;
+        _strip.SelectionChanged += ButtonsOptionControl_SelectionChanged;
 
-        Content = _tabStrip;
+        Content = this._strip;
     }
 
-    private void ButtonsOptionControl_SelectionChanged(object? sender, SelectionChangedEventArgs e)
+    private void ButtonsOptionControl_SelectionChanged(object? sender, EventArgs e)
     {
         OnChanged();
     }
 
     public string? GetValue()
     {
-        return _tabStrip.SelectedValue as string;
+        return _strip.SelectedItem as string;
     }
 
     public void SetValue(string value)
     {
-        _tabStrip.SelectedValue = value;
+        var item = _strip.Items.FirstOrDefault(x => Equals(x.Tag, value));
+        _strip.SelectedIndex = item is not null ? _strip.Items.IndexOf(item) : -1;
     }
 
     public bool IsEmpty() => GetValue() == null;