From c5a503ade2527229cd8304eee0ae5a7d93eb0a26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Peyronnet?= Date: Sat, 20 Nov 2021 14:27:05 +0100 Subject: [PATCH] Added the possibility to remove an item from the history in "Palette" page (#74) --- ColorPicker/Pages/PalettePage.xaml.cs | 4 +- .../UserControls/PaletteHistoryItem.xaml | 101 ++++++++++-------- .../UserControls/PaletteHistoryItem.xaml.cs | 10 +- 3 files changed, 68 insertions(+), 47 deletions(-) diff --git a/ColorPicker/Pages/PalettePage.xaml.cs b/ColorPicker/Pages/PalettePage.xaml.cs index e1ef296..b93a52d 100644 --- a/ColorPicker/Pages/PalettePage.xaml.cs +++ b/ColorPicker/Pages/PalettePage.xaml.cs @@ -41,7 +41,7 @@ public partial class PalettePage : Page { RGB[] CurrentColorPalette { get; set; } string CurrentRGBColor { get; set; } - List SavedColorPalettes { get; set; } + internal List SavedColorPalettes { get; set; } public PalettePage() { InitializeComponent(); @@ -238,7 +238,7 @@ private void AddToHistoryBtn_Click(object sender, RoutedEventArgs e) if (!SavedColorPalettes.Contains(CurrentRGBColor)) { SavedColorPalettes.Add(CurrentRGBColor); // Add to saved palettes - HistoryDisplayer.Children.Add(new PaletteHistoryItem(CurrentColorPalette)); + HistoryDisplayer.Children.Add(new PaletteHistoryItem(CurrentColorPalette, HistoryDisplayer)); } } } diff --git a/ColorPicker/UserControls/PaletteHistoryItem.xaml b/ColorPicker/UserControls/PaletteHistoryItem.xaml index ddbfce4..c341f26 100644 --- a/ColorPicker/UserControls/PaletteHistoryItem.xaml +++ b/ColorPicker/UserControls/PaletteHistoryItem.xaml @@ -4,50 +4,63 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:ColorPicker.UserControls" + xmlns:lang="clr-namespace:ColorPicker.Properties" mc:Ignorable="d" Width="300"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ColorPicker/UserControls/PaletteHistoryItem.xaml.cs b/ColorPicker/UserControls/PaletteHistoryItem.xaml.cs index d9584a6..8647f25 100644 --- a/ColorPicker/UserControls/PaletteHistoryItem.xaml.cs +++ b/ColorPicker/UserControls/PaletteHistoryItem.xaml.cs @@ -36,10 +36,12 @@ namespace ColorPicker.UserControls public partial class PaletteHistoryItem : UserControl { internal RGB[] Colors { get; init; } - public PaletteHistoryItem(RGB[] colors) + private StackPanel ParentStackPanel { get; init; } + public PaletteHistoryItem(RGB[] colors, StackPanel parent) { InitializeComponent(); Colors = colors; + ParentStackPanel = parent; // Set InitUI(); // Load the UI } @@ -73,5 +75,11 @@ private void ColorB1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) var color = ((SolidColorBrush)border.Background).Color; // Get background color Clipboard.SetText($"{color.R}{Global.Settings.RGBSeparator}{color.G}{Global.Settings.RGBSeparator}{color.B}"); // Copy } + + private void DeleteBtn_Click(object sender, RoutedEventArgs e) + { + Global.PalettePage.SavedColorPalettes.Remove($"{Colors[7].R};{Colors[7].G};{Colors[7].B}"); // Remove from virtual history + ParentStackPanel.Children.Remove(this); // Remove color palette + } } }