PhotoBox.xaml.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace ivf_tl_Operate.CustomUserControls
  16. {
  17. /// <summary>
  18. /// PhotoBox.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class PhotoBox : UserControl
  21. {
  22. public PhotoBox()
  23. {
  24. InitializeComponent();
  25. }
  26. public ImageSource ImageSource
  27. {
  28. get { return (ImageSource)GetValue(ImageSourceProperty); }
  29. set { SetValue(ImageSourceProperty, value); }
  30. }
  31. // Using a DependencyProperty as the backing store for ImageSource. This enables animation, styling, binding, etc...
  32. public static readonly DependencyProperty ImageSourceProperty =
  33. DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(PhotoBox), new PropertyMetadata(null));
  34. ///// <summary>
  35. ///// 图片地址
  36. ///// </summary>
  37. //public string ImageSource
  38. //{
  39. // get { return (string)GetValue(ImageSourceProperty); }
  40. // set { SetValue(ImageSourceProperty, value); }
  41. //}
  42. //public static readonly DependencyProperty ImageSourceProperty =
  43. // DependencyProperty.Register("ImageSource", typeof(string), typeof(PhotoBox), new PropertyMetadata("", new PropertyChangedCallback(ImageSourcePropertyChangedCallback)));
  44. private static void ImageSourcePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  45. {
  46. if (!(d is PhotoBox source)) return;
  47. if (!(e.NewValue is string uri)) return;
  48. if (string.IsNullOrEmpty(uri)) return;
  49. //if (uri == "null")
  50. // source._image.Source = null;
  51. //else
  52. //source._image.Source = FileHelper.GetBitmapImage(uri);
  53. //source._image.Source = new BitmapImage(new Uri(uri, UriKind.RelativeOrAbsolute));
  54. //source._image.Source = source.ChangeImage(uri);
  55. /*
  56. source.Dispatcher.BeginInvoke((Action)(() =>
  57. {
  58. BitmapImage bitmap = new BitmapImage();
  59. bitmap.BeginInit();
  60. bitmap.CacheOption = BitmapCacheOption.OnLoad;
  61. bitmap.StreamSource = new MemoryStream(File.ReadAllBytes(uri));
  62. bitmap.EndInit();
  63. bitmap.Freeze();
  64. source._image.Source = bitmap;
  65. source._image.Stretch = Stretch.UniformToFill;
  66. }));*/
  67. //using (var stream = new FileStream(uri, FileMode.Open))
  68. //{
  69. // BitmapImage bitmap = new BitmapImage();
  70. // bitmap.BeginInit();
  71. // bitmap.StreamSource = stream;
  72. // bitmap.CacheOption = BitmapCacheOption.OnLoad;
  73. // bitmap.EndInit();
  74. // bitmap.Freeze();
  75. // if (source._image != null)
  76. // source._image.Source = bitmap;
  77. //}
  78. }
  79. /// <summary>
  80. /// 是否显示打勾图标
  81. /// </summary>
  82. public bool IsShowYes
  83. {
  84. get { return (bool)GetValue(IsShowYesProperty); }
  85. set { SetValue(IsShowYesProperty, value); }
  86. }
  87. public static readonly DependencyProperty IsShowYesProperty =
  88. DependencyProperty.Register("IsShowYes", typeof(bool), typeof(PhotoBox), new PropertyMetadata(false, new PropertyChangedCallback(IsShowYesPropertyChangedCallback)));
  89. private static void IsShowYesPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  90. {
  91. if (!(d is PhotoBox source)) return;
  92. if (!(e.NewValue is bool show)) return;
  93. if (source._imageYes == null) return;
  94. if (show == true)
  95. source._imageYes.Visibility = Visibility.Visible;
  96. else
  97. source._imageYes.Visibility = Visibility.Collapsed;
  98. }
  99. /// <summary>
  100. /// 是否显示打叉图标
  101. /// </summary>
  102. public bool IsShowNo
  103. {
  104. get { return (bool)GetValue(IsShowNoProperty); }
  105. set { SetValue(IsShowNoProperty, value); }
  106. }
  107. public static readonly DependencyProperty IsShowNoProperty =
  108. DependencyProperty.Register("IsShowNo", typeof(bool), typeof(PhotoBox), new PropertyMetadata(false, new PropertyChangedCallback(IsShowNoPropertyChangedCallback)));
  109. private static void IsShowNoPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  110. {
  111. if (!(d is PhotoBox source)) return;
  112. if (!(e.NewValue is bool show)) return;
  113. if (source._imageNo == null) return;
  114. if (show == true)
  115. source._imageNo.Visibility = Visibility.Visible;
  116. else
  117. source._imageNo.Visibility = Visibility.Collapsed;
  118. }
  119. /// <summary>
  120. /// 是否显示冻结图标
  121. /// </summary>
  122. public bool IsShowFreezable
  123. {
  124. get { return (bool)GetValue(IsShowFreezableProperty); }
  125. set { SetValue(IsShowFreezableProperty, value); }
  126. }
  127. public static readonly DependencyProperty IsShowFreezableProperty =
  128. DependencyProperty.Register("IsShowFreezable", typeof(bool), typeof(PhotoBox), new PropertyMetadata(false, new PropertyChangedCallback(IsShowFreezablePropertyChangedCallback)));
  129. private static void IsShowFreezablePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  130. {
  131. if (!(d is PhotoBox source)) return;
  132. if (!(e.NewValue is bool show)) return;
  133. if (source._imageFreezable == null) return;
  134. if (show == true)
  135. source._imageFreezable.Visibility = Visibility.Visible;
  136. else
  137. source._imageFreezable.Visibility = Visibility.Collapsed;
  138. }
  139. /// <summary>
  140. /// 是否显示更多图标(此图标可替换图标内容如2PN,4PN,8PN...)
  141. /// </summary>
  142. public bool IsShowMore
  143. {
  144. get { return (bool)GetValue(IsShowMoreProperty); }
  145. set { SetValue(IsShowMoreProperty, value); }
  146. }
  147. public static readonly DependencyProperty IsShowMoreProperty =
  148. DependencyProperty.Register("IsShowMore", typeof(bool), typeof(PhotoBox), new PropertyMetadata(false, new PropertyChangedCallback(IsShowMorePropertyChangedCallback)));
  149. private static void IsShowMorePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  150. {
  151. if (!(d is PhotoBox source)) return;
  152. if (!(e.NewValue is bool show)) return;
  153. if (source._imageMore == null) return;
  154. if (show == true)
  155. source._imageMore.Visibility = Visibility.Visible;
  156. else
  157. source._imageMore.Visibility = Visibility.Collapsed;
  158. }
  159. /// <summary>
  160. /// PN图标地址源
  161. /// </summary>
  162. public string MoreImageSource
  163. {
  164. get { return (string)GetValue(MoreImageSourceProperty); }
  165. set { SetValue(MoreImageSourceProperty, value); }
  166. }
  167. public static readonly DependencyProperty MoreImageSourceProperty =
  168. DependencyProperty.Register("MoreImageSource", typeof(string), typeof(PhotoBox), new PropertyMetadata(null, new PropertyChangedCallback(MoreImageSourcePropertyChangedCallback)));
  169. private static void MoreImageSourcePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  170. {
  171. if (!(d is PhotoBox source)) return;
  172. if (!(e.NewValue is string uri)) return;
  173. if (string.IsNullOrEmpty(uri)) return;
  174. if (source._imageMore == null) return;
  175. try
  176. {
  177. source._imageMore.Source = new BitmapImage(new Uri(uri, UriKind.RelativeOrAbsolute));
  178. }
  179. catch (Exception ex)
  180. {
  181. throw new Exception(ex.Message);
  182. }
  183. }
  184. /// <summary>
  185. /// 图标编号
  186. /// </summary>
  187. public long ID
  188. {
  189. get { return (long)GetValue(IDProperty); }
  190. set { SetValue(IDProperty, value); }
  191. }
  192. public static readonly DependencyProperty IDProperty =
  193. DependencyProperty.Register("ID", typeof(long), typeof(PhotoBox), new PropertyMetadata(1L, new PropertyChangedCallback(IDPropertyChangedCallback)));
  194. private static void IDPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  195. {
  196. if (!(d is PhotoBox source)) return;
  197. if (!(e.NewValue is long id)) return;
  198. if (id <= 0) return;
  199. if (source._textId == null) return;
  200. source._textId.Text = id.ToString();
  201. }
  202. public string peiYangShiChang
  203. {
  204. get { return (string)GetValue(peiYangShiChangProperty); }
  205. set { SetValue(peiYangShiChangProperty, value); }
  206. }
  207. // Using a DependencyProperty as the backing store for peiYangShiChang. This enables animation, styling, binding, etc...
  208. public static readonly DependencyProperty peiYangShiChangProperty =
  209. DependencyProperty.Register("peiYangShiChang", typeof(string), typeof(PhotoBox), new PropertyMetadata("0h:0m", new PropertyChangedCallback(peiYangShiChangPropertyChangedCallback)));
  210. private static void peiYangShiChangPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  211. {
  212. if (!(d is PhotoBox source)) return;
  213. if (source._textTime == null) return;
  214. source._textTime.Text = e.NewValue.ToString();
  215. }
  216. /// <summary>
  217. /// 图片时间
  218. /// </summary>
  219. public DateTime CreationTime { get; set; }
  220. }
  221. }