MetroTileBackgroundConverter.cs 1.9 KB

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