private void setupColorPalette(Button btn) { Button[] swatchesButton = { btn50, btn100, btn200, btn300, btn400, btn500, btn600, btn700, btn800, btn900,btnA100, btnA200, btnA400, btnA700 }; String colorHex; colorGroup.Content = MaterialColorsEngine.getColorGroup(btn.Tag); if (Convert.ToInt32(btn.Tag) >= 16) { btnA100.Visibility = Visibility.Hidden; btnA200.Visibility = Visibility.Hidden; btnA400.Visibility = Visibility.Hidden; btnA700.Visibility = Visibility.Hidden; } else { btnA100.Visibility = Visibility.Visible; btnA200.Visibility = Visibility.Visible; btnA400.Visibility = Visibility.Visible; btnA700.Visibility = Visibility.Visible; } for (int i = 0; i < 14; i++) { if (Convert.ToInt32(btn.Tag) >= 16 && i >= 10) { break; } colorHex = MaterialColorsEngine.getMaterialColor(btn.Tag, i); grid = (Grid)VisualTreeHelper.GetChild(swatchesButton[i], 0); rectangle = (Rectangle)VisualTreeHelper.GetChild(grid, 0); labelColorNum = (Label)VisualTreeHelper.GetChild(grid, 1); labelHex = (Label)VisualTreeHelper.GetChild(grid, 2); // Set content labelHex.Content = colorHex; // Calculate readable color value Color backColor = (Color)ColorConverter.ConvertFromString(colorHex); Color foreColor = (perceivedBrightness(backColor) > 130 ? Colors.Black : Colors.White); // Set colors rectangle.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(colorHex)); labelColorNum.Foreground = new SolidColorBrush(foreColor); labelHex.Foreground = new SolidColorBrush(foreColor); } }
private void setupColorPalette(Button btn) { Button[] swatchesButton = { btn50, btn100, btn200, btn300, btn400, btn500, btn600, btn700, btn800, btn900,btnA100, btnA200, btnA400, btnA700 }; String colorHex; colorGroup.Content = MaterialColorsEngine.getColorGroup(btn.Tag); if (Convert.ToInt32(btn.Tag) >= 16) { btnA100.Visibility = Visibility.Hidden; btnA200.Visibility = Visibility.Hidden; btnA400.Visibility = Visibility.Hidden; btnA700.Visibility = Visibility.Hidden; } else { btnA100.Visibility = Visibility.Visible; btnA200.Visibility = Visibility.Visible; btnA400.Visibility = Visibility.Visible; btnA700.Visibility = Visibility.Visible; } for (int i = 0; i < 14; i++) { if (Convert.ToInt32(btn.Tag) >= 16 && i >= 10) { break; } colorHex = MaterialColorsEngine.getMaterialColor(btn.Tag, i); grid = (Grid)VisualTreeHelper.GetChild(swatchesButton[i], 0); rectangle = (Rectangle)VisualTreeHelper.GetChild(grid, 0); labelHex = (Label)VisualTreeHelper.GetChild(grid, 2); rectangle.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(colorHex)); labelHex.Content = colorHex; } }