TileBackgroundConverter.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Globalization;
  3. using System.Windows.Data;
  4. using System.Windows.Media;
  5. namespace MediaBrowser.Plugins.DefaultTheme.Converters
  6. {
  7. public class TileBackgroundConverter : IValueConverter
  8. {
  9. private static readonly Brush[] TileColors = new Brush[] {
  10. new SolidColorBrush(Color.FromRgb((byte)111,(byte)189,(byte)69)),
  11. new SolidColorBrush(Color.FromRgb((byte)75,(byte)179,(byte)221)),
  12. new SolidColorBrush(Color.FromRgb((byte)65,(byte)100,(byte)165)),
  13. new SolidColorBrush(Color.FromRgb((byte)225,(byte)32,(byte)38)),
  14. new SolidColorBrush(Color.FromRgb((byte)128,(byte)0,(byte)128)),
  15. new SolidColorBrush(Color.FromRgb((byte)0,(byte)128,(byte)64)),
  16. new SolidColorBrush(Color.FromRgb((byte)0,(byte)148,(byte)255)),
  17. new SolidColorBrush(Color.FromRgb((byte)255,(byte)0,(byte)199)),
  18. new SolidColorBrush(Color.FromRgb((byte)255,(byte)135,(byte)15)),
  19. new SolidColorBrush(Color.FromRgb((byte)127,(byte)0,(byte)55))
  20. };
  21. private static int _currentIndex = new Random(DateTime.Now.Millisecond).Next(0, TileColors.Length);
  22. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  23. {
  24. int index;
  25. lock (TileColors)
  26. {
  27. index = (_currentIndex++) % TileColors.Length;
  28. }
  29. return TileColors[index++];
  30. }
  31. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  32. {
  33. throw new System.NotImplementedException();
  34. }
  35. }
  36. }