Переглянути джерело

Fixed selectable strip not restoring visual state

Krzysztof Krysiński 5 днів тому
батько
коміт
9228f2346b

+ 16 - 0
src/PixiEditor.UI.Common/Controls/SelectableStrip.cs

@@ -2,6 +2,7 @@
 using Avalonia.Animation;
 using Avalonia.Animation.Easings;
 using Avalonia.Controls;
+using Avalonia.Controls.Presenters;
 using Avalonia.Layout;
 using Avalonia.Media;
 using Avalonia.Styling;
@@ -86,6 +87,8 @@ public class SelectableStrip : Panel
         {
             Children.Insert(0, _highlight);
         }
+
+        FindSelectedItem();
     }
 
     private static void OnSelectionChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
@@ -110,6 +113,19 @@ public class SelectableStrip : Panel
         selectableStrip.HighlightX = pos.X;
     }
 
+    private void FindSelectedItem()
+    {
+        foreach (var child in Children)
+        {
+            if (child is ContentPresenter presenter && presenter.Child != null && GetIsStripSelected(presenter.Child))
+            {
+                var pos = presenter.Child.TranslatePoint(new Point(0, 0), this) ?? new Point();
+                HighlightX = pos.X;
+                break;
+            }
+        }
+    }
+
     protected override Size ArrangeOverride(Size finalSize)
     {
         double x = 0;

+ 1 - 1
src/PixiEditor/Views/Tools/ToolSettings/Settings/EnumSettingView.axaml

@@ -19,7 +19,7 @@
         <ComboBox VerticalAlignment="Center"
                   MinWidth="85"
                   IsVisible="{Binding !PickerIsIconButtons}"
-                  SelectedIndex="{Binding Value, Mode=TwoWay}"
+                  SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}"
                   ItemsSource="{Binding EnumValues}">
             <ComboBox.ItemContainerTheme>
                 <ControlTheme TargetType="ComboBoxItem" BasedOn="{StaticResource {x:Type ComboBoxItem}}">