PageRenderTime 36ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/GammaJul.LgLcd.Samples.Wpf/SampleControl.xaml.cs

#
C# | 51 lines | 32 code | 6 blank | 13 comment | 6 complexity | 2dbe9a6a7158454b72f07184c58b1ab1 MD5 | raw file
Possible License(s): LGPL-2.1
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Windows.Media;
  5. using System.Windows.Media.Imaging;
  6. namespace GammaJul.LgLcd.Samples.Wpf {
  7. /// <summary>
  8. /// This simple controls loads images from the %windir%\Web\Wallpaper directory
  9. /// and provides function to switch between them.
  10. /// </summary>
  11. public partial class SampleControl {
  12. private readonly List<ImageSource> _images = new List<ImageSource>();
  13. private int _currentIndex = -1;
  14. /// <summary>
  15. /// Switch to the previous image.
  16. /// </summary>
  17. public void PreviousImage() {
  18. if (_images.Count == 0)
  19. return;
  20. if (--_currentIndex < 0)
  21. _currentIndex = _images.Count - 1;
  22. Img.Source = _images[_currentIndex];
  23. }
  24. /// <summary>
  25. /// Switch to the next image.
  26. /// </summary>
  27. public void NextImage() {
  28. if (_images.Count == 0)
  29. return;
  30. if (++_currentIndex >= _images.Count)
  31. _currentIndex = 0;
  32. Img.Source = _images[_currentIndex];
  33. }
  34. /// <summary>
  35. /// Creates a new <see cref="SampleControl"/>.
  36. /// </summary>
  37. public SampleControl() {
  38. InitializeComponent();
  39. string wallpaperPath = Path.Combine(Path.GetDirectoryName(Environment.GetFolderPath(Environment.SpecialFolder.System)), "Web\\Wallpaper");
  40. foreach (string file in Directory.GetFiles(wallpaperPath, "*.jpg", SearchOption.AllDirectories))
  41. _images.Add(new BitmapImage(new Uri(file, UriKind.Absolute)));
  42. NextImage();
  43. }
  44. }
  45. }