Browse Source

Fixed associated key not updating on swap

Krzysztof Krysiński 1 year ago
parent
commit
61eca8ba08

+ 1 - 1
src/PixiEditor.AvaloniaUI/Views/Palettes/PaletteViewer.axaml

@@ -66,7 +66,7 @@
                 <TextBlock TextWrapping="Wrap" ui:Translator.Key="DROP_PALETTE" Foreground="White" FontSize="32" HorizontalAlignment="Center" VerticalAlignment="Center"/>
             </Grid>
             <ScrollViewer Grid.Row="2" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
-                <ItemsControl ItemsSource="{Binding Colors, ElementName=paletteControl}">
+                <ItemsControl Name="PaletteItemsSource" ItemsSource="{Binding Colors, ElementName=paletteControl}">
                     <ItemsControl.ItemsPanel>
                         <ItemsPanelTemplate>
                             <WrapPanel Margin="10" Orientation="Horizontal"

+ 8 - 0
src/PixiEditor.AvaloniaUI/Views/Palettes/PaletteViewer.axaml.cs

@@ -113,6 +113,7 @@ internal partial class PaletteViewer : UserControl
         if (Colors.Contains(colorControl))
         {
             Colors.Remove(colorControl);
+            RefreshAllItems();
         }
     }
 
@@ -257,11 +258,18 @@ internal partial class PaletteViewer : UserControl
                     int newIndex = Colors.IndexOf(paletteColorControl.Color);
                     Colors.RemoveAt(currIndex);
                     Colors.Insert(newIndex, paletteColor);
+                    RefreshAllItems();
                 }
             }
         }
     }
 
+    private void RefreshAllItems()
+    {
+        PaletteItemsSource.ItemsSource = null;
+        PaletteItemsSource.ItemsSource = Colors;
+    }
+
     private async void BrowsePalettes_Click(object sender, RoutedEventArgs e)
     {
         var browser = PalettesBrowser.Open(PaletteProvider, ImportPaletteCommand, Colors);