private void MergeSelectedColorsBtn_Click(object sender, RoutedEventArgs e) { if (SelectedCells.Count == 0) { return; } var avgColor = ColorPalette.GetAverage(SelectedCells.Select(c => (c.Background as SolidColorBrush).Color).ToArray()); var newColors = new List <Color>(); newColors.Add(avgColor); foreach (var color in Colors) { if (SelectedCells.Any(sc => ColorPalette.CompareColors(color, (sc.Background as SolidColorBrush).Color))) { continue; } newColors.Add(color); } Colors = ColorPalette.Sort(newColors.ToArray()); CreatePalette(RowLength); }