| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- using ivf_tl_Entity.GlobalEntitys;
- using ivf_tl_Operate.CustomUserControls;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- namespace ivf_tl_Operate.Windows
- {
- /// <summary>
- /// PhotoWindowNew.xaml 的交互逻辑
- /// </summary>
- public partial class PhotoWindowNew : Window
- {
- public PictureView currentPhoto = null;
- public bool isSource = false;
- public PhotoWindowNew(ObservableCollection<PictureView> photoBoxes, long id,bool _isSource)
- {
- InitializeComponent();
- this.Owner = AppData.Instance.MainWindow;
- //CurrentEmbryo = embryo;
- Photos = new List<PictureView>(photoBoxes);
- isSource = _isSource;
- var a = Photos.FirstOrDefault(x => x.Num == id);
- if (a == null) return;
- currentPhoto = a;
- CurrentNum = Photos.IndexOf(currentPhoto);
- InitPic();
- }
- public void InitPic()
- {
- TransformGroup transformGroup = new TransformGroup();
- ScaleTransform sfr = new ScaleTransform();//缩放
- transformGroup.Children.Add(sfr);
- TranslateTransform ttf = new TranslateTransform();//平移
- transformGroup.Children.Add(ttf);
- string imageurl = currentPhoto.imageUrl;
- if (isSource) imageurl = currentPhoto.sourceImageUrl;
- Image currentImage = new Image
- {
- Source = AppData.Instance.ConvertHelper.StringToBitmapImage($"{AppData.Instance.BaseUrl}{imageurl}?token={AppData.Instance.HttpHelper.GetToken()}"),
- Cursor = Cursors.Hand,
- RenderTransform = transformGroup,
- };
- currentImage.MouseWheel += (s, arg) =>
- {
- Point centerPoint = arg.GetPosition(_container);
- sfr.CenterX = centerPoint.X;
- sfr.CenterY = centerPoint.Y;
- var delta = arg.Delta * 0.001;
- if (sfr.ScaleX + delta < 0.1) return;
- if (sfr.ScaleX + delta > 4.0) return;
- sfr.ScaleX += arg.Delta * 0.001;
- sfr.ScaleY += arg.Delta * 0.001;
- };
- Point StartPosition = new Point();
- Point EndPosition = new Point();
- currentImage.MouseDown += (s, arg) =>
- {
- StartPosition = arg.GetPosition(currentImage);
- };
- currentImage.MouseMove += (s, arg) =>
- {
- if (arg.LeftButton != MouseButtonState.Pressed) return;
- EndPosition = arg.GetPosition(currentImage);
- var X = EndPosition.X - StartPosition.X;
- var Y = EndPosition.Y - StartPosition.Y;
- ttf.X += X;
- ttf.Y += Y;
- };
- this._container.Child = currentImage;
- //this._textbox.Text = currentPhoto.Name;
- }
- public int CurrentNum
- {
- get { return (int)GetValue(CurrentNumProperty); }
- set { SetValue(CurrentNumProperty, value); }
- }
- // Using a DependencyProperty as the backing store for CurrentNum. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty CurrentNumProperty =
- DependencyProperty.Register("CurrentNum", typeof(int), typeof(PhotoWindowNew), new PropertyMetadata(-1));
- public int AllPicNum
- {
- get { return (int)GetValue(AllPicNumProperty); }
- set { SetValue(AllPicNumProperty, value); }
- }
- // Using a DependencyProperty as the backing store for AllPicNum. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty AllPicNumProperty =
- DependencyProperty.Register("AllPicNum", typeof(int), typeof(PhotoWindowNew), new PropertyMetadata(0));
- public List<PictureView> Photos
- {
- get { return (List<PictureView>)GetValue(PhotosProperty); }
- set { SetValue(PhotosProperty, value); }
- }
- // Using a DependencyProperty as the backing store for Photos. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty PhotosProperty =
- DependencyProperty.Register("Photos", typeof(List<PictureView>), typeof(PhotoWindowNew), new PropertyMetadata(new List<PictureView>(), new PropertyChangedCallback(PhotosPropertyChanged)));
- private static void PhotosPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (!(d is PhotoWindowNew source)) return;
- if (!(e.NewValue is List<PictureView> newValue))
- {
- return;
- }
- source.AllPicNum = newValue.Count;
- }
- private void ZoomMax_MouseUp(object sender, MouseButtonEventArgs e)
- {
- Image image = this._container.Child as Image;
- if (image == null) return;
- TransformGroup transformGroup = image.RenderTransform as TransformGroup;
- ScaleTransform scaleTransform = transformGroup.Children[0] as ScaleTransform;
- scaleTransform.CenterX = 560;
- scaleTransform.CenterY = 560;
- scaleTransform.ScaleX += 0.1;
- scaleTransform.ScaleY += 0.1;
- }
- private void ZoomMin_MouseUp(object sender, MouseButtonEventArgs e)
- {
- Image image = this._container.Child as Image;
- if (image == null) return;
- TransformGroup transformGroup = image.RenderTransform as TransformGroup;
- ScaleTransform scaleTransform = transformGroup.Children[0] as ScaleTransform;
- scaleTransform.CenterX = 560;
- scaleTransform.CenterY = 560;
- if (scaleTransform.ScaleX > 0.1)
- {
- scaleTransform.ScaleX -= 0.1;
- scaleTransform.ScaleY -= 0.1;
- }
- }
- private void Image_MouseUp(object sender, MouseButtonEventArgs e)
- {
- this.Close();
- }
- private void SingleImageExport_MouseUp(object sender, MouseButtonEventArgs e)
- {
- }
- private void PreviousPic_MouseUp(object sender, MouseButtonEventArgs e)
- {
- if (CurrentNum == -1)
- {
- CurrentNum = Photos.IndexOf(currentPhoto);
- if (CurrentNum > 0)
- {
- currentPhoto = Photos[--CurrentNum];
- InitPic();
- }
- }
- else
- {
- if (CurrentNum > 0)
- {
- currentPhoto = Photos[--CurrentNum];
- InitPic();
- }
- }
- }
- private void NextPic_MouseUp(object sender, MouseButtonEventArgs e)
- {
- if (CurrentNum == -1)
- {
- CurrentNum = Photos.IndexOf(currentPhoto);
- if (CurrentNum != -1 && CurrentNum < (Photos.Count - 1))
- {
- currentPhoto = Photos[++CurrentNum];
- InitPic();
- }
- }
- else
- {
- if (CurrentNum < (Photos.Count - 1))
- {
- currentPhoto = Photos[++CurrentNum];
- InitPic();
- }
- }
- }
- }
- }
|