ThumbnailContainer.xaml.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using MediaViewerLib.Utilities;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Animation;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. namespace HistoryDLL
  19. {
  20. /// <summary>
  21. /// ThumbnailContainer.xaml 的互動邏輯
  22. /// </summary>
  23. public partial class ThumbnailContainer : UserControl
  24. {
  25. private Storyboard sbShowStart;
  26. private Storyboard sbShowStop;
  27. private List<string> imgPath;
  28. private int imgWidth = 211;
  29. private int imgHeight = 158;
  30. private int topBottomDiff = 10;
  31. public List<string> ImgPath
  32. {
  33. get { return imgPath; }
  34. set
  35. {
  36. imgPath = value;
  37. LoadThumbImage();
  38. }
  39. }
  40. public ThumbnailContainer()
  41. {
  42. InitializeComponent();
  43. if (GlobalFunction.isSolutionUsing4K)
  44. {
  45. imgWidth *= 2;
  46. imgHeight *= 2;
  47. //topBottomDiff *= 2;
  48. }
  49. sbShowStart = FindResource("sbShowStart") as Storyboard;
  50. sbShowStart.Completed += new EventHandler(sbShowStart_Completed);
  51. sbShowStop = FindResource("sbShowStop") as Storyboard;
  52. sbShowStop.Completed += new EventHandler(sbShowStop_Completed);
  53. }
  54. private void sbShowStop_Completed(object sender, EventArgs e)
  55. {
  56. uxStackPanel.Opacity = 0.0;
  57. }
  58. private void sbShowStart_Completed(object sender, EventArgs e)
  59. {
  60. uxStackPanel.Opacity = 1.0;
  61. }
  62. public void StartOpacityAnimation()
  63. {
  64. if (sbShowStart != null)
  65. {
  66. sbShowStart.Begin();
  67. }
  68. }
  69. public void StopOpacityAnimation()
  70. {
  71. if (sbShowStop != null)
  72. {
  73. sbShowStop.Begin();
  74. }
  75. }
  76. private void LoadThumbImage()
  77. {
  78. uxStackPanel.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
  79. SolidColorBrush brush = new SolidColorBrush(ConfigSettingClass.EventCollect.BackgroundColor);
  80. if (imgPath.Count == 0)
  81. {
  82. Image img = new Image();
  83. if (File.Exists(GlobalFunction.thumbPath + ConfigSettingClass.MainBackCollect.ImgLogo))
  84. {
  85. Grid gd = new Grid();
  86. Rectangle rectange = new Rectangle();
  87. //ImageBrush imagebrush = new ImageBrush(new BitmapImage(new Uri(@"pack://application:,,,/" + GlobalFunction.projectname + @";component/Data/Thumb/shadow_big.png", UriKind.RelativeOrAbsolute)));
  88. ImageBrush imagebrush = null;
  89. gd.Width = imgWidth + (GlobalFunction.isSolutionUsing4K ? 8 : 5);
  90. gd.Height = imgHeight + (GlobalFunction.isSolutionUsing4K ? 8 : 5);
  91. //imagebrush.Stretch = Stretch.Fill;
  92. //gd.Background = imagebrush;
  93. gd.Background =Brushes.Gray;
  94. gd.VerticalAlignment = System.Windows.VerticalAlignment.Center;
  95. gd.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
  96. rectange.VerticalAlignment = System.Windows.VerticalAlignment.Top;
  97. rectange.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
  98. img.Width = rectange.Width = imgWidth;
  99. img.Height = rectange.Height = imgHeight;
  100. //img.Margin = new Thickness(-(GlobalFunction.isSolutionUsing4K ? 10 : 5), -(GlobalFunction.isSolutionUsing4K ? 10 : 5), 0, 0);
  101. img.Margin = rectange.Margin = new Thickness(3, 2, 0, 0);
  102. img.Source = new BitmapImage(new Uri(GlobalFunction.thumbPath + ConfigSettingClass.MainBackCollect.ImgLogo));
  103. rectange.Fill = brush;
  104. gd.Children.Add(rectange);
  105. gd.Children.Add(img);
  106. gd.Margin = GlobalFunction.isSolutionUsing4K ? new Thickness(0, 0, 0, topBottomDiff) : new Thickness(0, 0, 0, 0);
  107. uxStackPanel.Children.Add(gd);
  108. }
  109. }
  110. else
  111. {
  112. for (int i = 0; i < imgPath.Count; i++)
  113. {
  114. BitmapSource src = MediaUtilties.LoadThumbnailImage(imgPath[i], ThumbnailSize.Large);
  115. Grid gd = new Grid();
  116. //ImageBrush imagebrush = new ImageBrush(new BitmapImage(new Uri(@"pack://application:,,,/" + GlobalFunction.projectname + @";component/Data/Thumb/shadow_big.png", UriKind.RelativeOrAbsolute)));
  117. ImageBrush imagebrush = new ImageBrush(new BitmapImage(new Uri(System.IO.Path.Combine(GlobalFunction.thumbPath,"shadow_big.png"), UriKind.RelativeOrAbsolute)));
  118. Image img = new Image();
  119. Rectangle rectange = new Rectangle();
  120. gd.Width = imgWidth + (GlobalFunction.isSolutionUsing4K ? 8 : 5);
  121. gd.Height = imgHeight + (GlobalFunction.isSolutionUsing4K ? 8 : 5);
  122. //gd.Background = new SolidColorBrush(Colors.Red);
  123. imagebrush.Stretch = Stretch.Fill;
  124. gd.Background = imagebrush;
  125. gd.VerticalAlignment = System.Windows.VerticalAlignment.Center;
  126. gd.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
  127. img.VerticalAlignment = rectange.VerticalAlignment = System.Windows.VerticalAlignment.Top;
  128. img.HorizontalAlignment = rectange.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
  129. img.Width = rectange.Width = imgWidth;
  130. img.Height = rectange.Height = imgHeight;
  131. img.Stretch = Stretch.UniformToFill;
  132. img.Source = src;
  133. rectange.Fill = brush;
  134. img.Margin = rectange.Margin = new Thickness(3, 2, 0, 0);
  135. //gd.Margin = new Thickness(0, topBottomDiff, 0, 0);
  136. gd.Children.Add(rectange);
  137. gd.Children.Add(img);
  138. gd.Margin = GlobalFunction.isSolutionUsing4K ? new Thickness(0, 0, 0, topBottomDiff) : new Thickness(0, 0, 0, 0);
  139. uxStackPanel.Children.Add(gd);
  140. }
  141. }
  142. }
  143. }
  144. }