PhotoWindowNew.xaml.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. using ivf_tl_Entity.GlobalEntitys;
  2. using ivf_tl_Operate.CustomUserControls;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Shapes;
  17. namespace ivf_tl_Operate.Windows
  18. {
  19. /// <summary>
  20. /// PhotoWindowNew.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class PhotoWindowNew : Window
  23. {
  24. public PictureView currentPhoto = null;
  25. public bool isSource = false;
  26. public PhotoWindowNew(ObservableCollection<PictureView> photoBoxes, long id,bool _isSource)
  27. {
  28. InitializeComponent();
  29. this.Owner = AppData.Instance.MainWindow;
  30. //CurrentEmbryo = embryo;
  31. Photos = new List<PictureView>(photoBoxes);
  32. isSource = _isSource;
  33. var a = Photos.FirstOrDefault(x => x.Num == id);
  34. if (a == null) return;
  35. currentPhoto = a;
  36. CurrentNum = Photos.IndexOf(currentPhoto);
  37. InitPic();
  38. }
  39. public void InitPic()
  40. {
  41. TransformGroup transformGroup = new TransformGroup();
  42. ScaleTransform sfr = new ScaleTransform();//缩放
  43. transformGroup.Children.Add(sfr);
  44. TranslateTransform ttf = new TranslateTransform();//平移
  45. transformGroup.Children.Add(ttf);
  46. string imageurl = currentPhoto.imageUrl;
  47. if (isSource) imageurl = currentPhoto.sourceImageUrl;
  48. Image currentImage = new Image
  49. {
  50. Source = AppData.Instance.ConvertHelper.StringToBitmapImage($"{AppData.Instance.BaseUrl}{imageurl}?token={AppData.Instance.HttpHelper.GetToken()}"),
  51. Cursor = Cursors.Hand,
  52. RenderTransform = transformGroup,
  53. };
  54. currentImage.MouseWheel += (s, arg) =>
  55. {
  56. Point centerPoint = arg.GetPosition(_container);
  57. sfr.CenterX = centerPoint.X;
  58. sfr.CenterY = centerPoint.Y;
  59. var delta = arg.Delta * 0.001;
  60. if (sfr.ScaleX + delta < 0.1) return;
  61. if (sfr.ScaleX + delta > 4.0) return;
  62. sfr.ScaleX += arg.Delta * 0.001;
  63. sfr.ScaleY += arg.Delta * 0.001;
  64. };
  65. Point StartPosition = new Point();
  66. Point EndPosition = new Point();
  67. currentImage.MouseDown += (s, arg) =>
  68. {
  69. StartPosition = arg.GetPosition(currentImage);
  70. };
  71. currentImage.MouseMove += (s, arg) =>
  72. {
  73. if (arg.LeftButton != MouseButtonState.Pressed) return;
  74. EndPosition = arg.GetPosition(currentImage);
  75. var X = EndPosition.X - StartPosition.X;
  76. var Y = EndPosition.Y - StartPosition.Y;
  77. ttf.X += X;
  78. ttf.Y += Y;
  79. };
  80. this._container.Child = currentImage;
  81. //this._textbox.Text = currentPhoto.Name;
  82. }
  83. public int CurrentNum
  84. {
  85. get { return (int)GetValue(CurrentNumProperty); }
  86. set { SetValue(CurrentNumProperty, value); }
  87. }
  88. // Using a DependencyProperty as the backing store for CurrentNum. This enables animation, styling, binding, etc...
  89. public static readonly DependencyProperty CurrentNumProperty =
  90. DependencyProperty.Register("CurrentNum", typeof(int), typeof(PhotoWindowNew), new PropertyMetadata(-1));
  91. public int AllPicNum
  92. {
  93. get { return (int)GetValue(AllPicNumProperty); }
  94. set { SetValue(AllPicNumProperty, value); }
  95. }
  96. // Using a DependencyProperty as the backing store for AllPicNum. This enables animation, styling, binding, etc...
  97. public static readonly DependencyProperty AllPicNumProperty =
  98. DependencyProperty.Register("AllPicNum", typeof(int), typeof(PhotoWindowNew), new PropertyMetadata(0));
  99. public List<PictureView> Photos
  100. {
  101. get { return (List<PictureView>)GetValue(PhotosProperty); }
  102. set { SetValue(PhotosProperty, value); }
  103. }
  104. // Using a DependencyProperty as the backing store for Photos. This enables animation, styling, binding, etc...
  105. public static readonly DependencyProperty PhotosProperty =
  106. DependencyProperty.Register("Photos", typeof(List<PictureView>), typeof(PhotoWindowNew), new PropertyMetadata(new List<PictureView>(), new PropertyChangedCallback(PhotosPropertyChanged)));
  107. private static void PhotosPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  108. {
  109. if (!(d is PhotoWindowNew source)) return;
  110. if (!(e.NewValue is List<PictureView> newValue))
  111. {
  112. return;
  113. }
  114. source.AllPicNum = newValue.Count;
  115. }
  116. private void ZoomMax_MouseUp(object sender, MouseButtonEventArgs e)
  117. {
  118. Image image = this._container.Child as Image;
  119. if (image == null) return;
  120. TransformGroup transformGroup = image.RenderTransform as TransformGroup;
  121. ScaleTransform scaleTransform = transformGroup.Children[0] as ScaleTransform;
  122. scaleTransform.CenterX = 560;
  123. scaleTransform.CenterY = 560;
  124. scaleTransform.ScaleX += 0.1;
  125. scaleTransform.ScaleY += 0.1;
  126. }
  127. private void ZoomMin_MouseUp(object sender, MouseButtonEventArgs e)
  128. {
  129. Image image = this._container.Child as Image;
  130. if (image == null) return;
  131. TransformGroup transformGroup = image.RenderTransform as TransformGroup;
  132. ScaleTransform scaleTransform = transformGroup.Children[0] as ScaleTransform;
  133. scaleTransform.CenterX = 560;
  134. scaleTransform.CenterY = 560;
  135. if (scaleTransform.ScaleX > 0.1)
  136. {
  137. scaleTransform.ScaleX -= 0.1;
  138. scaleTransform.ScaleY -= 0.1;
  139. }
  140. }
  141. private void Image_MouseUp(object sender, MouseButtonEventArgs e)
  142. {
  143. this.Close();
  144. }
  145. private void SingleImageExport_MouseUp(object sender, MouseButtonEventArgs e)
  146. {
  147. }
  148. private void PreviousPic_MouseUp(object sender, MouseButtonEventArgs e)
  149. {
  150. if (CurrentNum == -1)
  151. {
  152. CurrentNum = Photos.IndexOf(currentPhoto);
  153. if (CurrentNum > 0)
  154. {
  155. currentPhoto = Photos[--CurrentNum];
  156. InitPic();
  157. }
  158. }
  159. else
  160. {
  161. if (CurrentNum > 0)
  162. {
  163. currentPhoto = Photos[--CurrentNum];
  164. InitPic();
  165. }
  166. }
  167. }
  168. private void NextPic_MouseUp(object sender, MouseButtonEventArgs e)
  169. {
  170. if (CurrentNum == -1)
  171. {
  172. CurrentNum = Photos.IndexOf(currentPhoto);
  173. if (CurrentNum != -1 && CurrentNum < (Photos.Count - 1))
  174. {
  175. currentPhoto = Photos[++CurrentNum];
  176. InitPic();
  177. }
  178. }
  179. else
  180. {
  181. if (CurrentNum < (Photos.Count - 1))
  182. {
  183. currentPhoto = Photos[++CurrentNum];
  184. InitPic();
  185. }
  186. }
  187. }
  188. }
  189. }