WeatherImageConverter.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using MediaBrowser.Model.Weather;
  2. using System;
  3. using System.Globalization;
  4. using System.Windows.Data;
  5. namespace MediaBrowser.Plugins.DefaultTheme.Converters
  6. {
  7. /// <summary>
  8. /// Generates a weather image based on the current forecast
  9. /// </summary>
  10. public class WeatherImageConverter : IValueConverter
  11. {
  12. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  13. {
  14. var weather = value as WeatherInfo;
  15. if (weather != null && weather.CurrentWeather != null)
  16. {
  17. switch (weather.CurrentWeather.Condition)
  18. {
  19. case WeatherConditions.Thunderstorm:
  20. return "../Resources/Images/Weather/Thunder.png";
  21. case WeatherConditions.Overcast:
  22. return "../Resources/Images/Weather/Overcast.png";
  23. case WeatherConditions.Mist:
  24. case WeatherConditions.Sleet:
  25. case WeatherConditions.Rain:
  26. return "../Resources/Images/Weather/Rain.png";
  27. case WeatherConditions.Blizzard:
  28. case WeatherConditions.Snow:
  29. return "../Resources/Images/Weather/Snow.png";
  30. case WeatherConditions.Cloudy:
  31. return "../Resources/Images/Weather/Cloudy.png";
  32. case WeatherConditions.PartlyCloudy:
  33. return "../Resources/Images/Weather/PartlyCloudy.png";
  34. default:
  35. return "../Resources/Images/Weather/Sunny.png";
  36. }
  37. }
  38. return null;
  39. }
  40. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  41. {
  42. throw new NotImplementedException();
  43. }
  44. }
  45. }