private void AddImage(PhotoInfo[] pis) { int imax = LayoutRoot.Children.Count; int icnt = 0; if (imax > 50) { LayoutRoot.Children.RemoveAt(1); LayoutRoot.Children.RemoveAt(1); LayoutRoot.Children.RemoveAt(1); } foreach (UIElement el in LayoutRoot.Children) { if (el.GetType() == typeof(Image)) { icnt++; Image elimg = (el as Image); elimg.RenderTransform = new SkewTransform() { AngleX = 360 - (imax - icnt), AngleY = 360 - (imax - icnt) }; double dop = double.Parse(icnt.ToString()) / double.Parse(imax.ToString()); elimg.Opacity = dop; } } int ipcnt = 0; foreach (PhotoInfo photoInfo in pis) { if (photoInfo != null) { Image img = new Image() { Source = photoInfo.ImageSource, Height = LayoutRoot.RowDefinitions[0].Height.Value - 150, Margin = new Thickness(30), VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = ipcnt == 0 ? HorizontalAlignment.Left : ipcnt == 1 ? HorizontalAlignment.Center : ipcnt == 2 ? HorizontalAlignment.Right : HorizontalAlignment.Stretch, Stretch = Stretch.Uniform }; img.SetValue(Grid.RowProperty, 0); LayoutRoot.Children.Add(img); ipcnt++; } } }
private void AddImage(string strImg) { if (!string.IsNullOrEmpty(strImg)) { PhotoInfo pi = new PhotoInfo(strImg, true); if (pi.id.Length > 0) { Image img = new Image { Name = pi.id, Width = ThumbnailSize.Width, Height = ThumbnailSize.Height, Margin = new Thickness(1), Stretch = System.Windows.Media.Stretch.Uniform }; img.Opacity = .01; pi.DownloadProgressChanged += (a, b) => { img.Opacity = b.ProgressPercentage * 1e-2; if(RotateOnLoading) img.RenderTransform = new RotateTransform() { Angle = b.ProgressPercentage * 3.6, CenterX = (img.Width / 2), CenterY = (img.Height / 2) }; System.GC.Collect(); }; pi.ImageSourceIsLoaded += (a, b) => { img.Opacity = 1; img.RenderTransform = null; if (AutoGotoNextDate) { var list1 = ImageWrapPanel.Children.Cast<Image>().Where(x => x.Tag != null && x.Tag.GetType() == typeof(PhotoInfo)); if (list1.All(x => (x.Tag as PhotoInfo).ImageIsLoaded)) PlayPauseClick(Statuses.Playing); } System.GC.Collect(); }; pi.SmallImageSourceIsLoaded += (a, b) => { img.Source = pi.SmallImageSource; try { //ImageWrapPanel.Children.Add(img); Random rnd = new Random(System.DateTime.Now.Millisecond); double didx = double.Parse(ImageWrapPanel.Children.Count.ToString()); didx = Math.Round(didx / 2); int idx = 0; switch (ImagePlacements) { case ImagePlacements.Random: idx = rnd.Next(0, ImageWrapPanel.Children.Count); //int.Parse(didx.ToString()); ImageWrapPanel.Children.Insert(idx, img); break; case ImagePlacements.Split: idx = int.Parse(didx.ToString()); ImageWrapPanel.Children.Insert(idx, img); break; case ImagePlacements.ZeroToEnd: ImageWrapPanel.Children.Add(img); break; } img.MouseLeftButtonDown += (a1, b1) => { WrapPanel spp = (WrapPanel)img.Parent; if (spp == null) return; int iThis = spp.Children.GetIndex(img); Image imgPrev = (iThis - 1) > 0 ? (Image)spp.Children.ElementAt<UIElement>(iThis - 1) : null; Image imgNext = (iThis + 1) < spp.Children.Count ? (Image)spp.Children.ElementAt<UIElement>(iThis + 1) : null; OnMouseDownImage(new MouseDownImageEventArgs() { image = img, photoinfo = pi, nextPhotoInfo = imgNext != null ? imgNext.Tag != null ? (PhotoInfo)imgNext.Tag : null : null, prevPhotoInfo = imgPrev != null ? imgPrev.Tag != null ? (PhotoInfo)imgPrev.Tag : null : null, point = b1.GetPosition(a1 as UIElement) }); }; img.MouseEnter += (a2, b2) => { WrapPanel spp = (WrapPanel)img.Parent; if (spp == null) return; int iThis = spp.Children.GetIndex(img); Image imgPrev = (iThis - 1) > 0 ? (Image)spp.Children.ElementAt<UIElement>(iThis - 1) : null; Image imgNext = (iThis + 1) < spp.Children.Count ? (Image)spp.Children.ElementAt<UIElement>(iThis + 1) : null; OnMouseEnterImage(new MouseEnterImageEventArgs() { image = img, photoinfo = pi, nextPhotoInfo = imgNext != null ? imgNext.Tag != null ? (PhotoInfo)imgNext.Tag : null : null, prevPhotoInfo = imgPrev != null ? imgPrev.Tag != null ? (PhotoInfo)imgPrev.Tag : null : null, point = b2.GetPosition(a2 as UIElement) }); }; } catch { } ImageSource isi = pi.ImageSource; }; img.Tag = pi; img.MouseLeave += (a, b) => { OnMouseLeaveImage(new MouseLeaveImageEventArgs() { image = img, photoinfo = pi, point = b.GetPosition(a as UIElement) }); }; img.ImageFailed += new EventHandler<ExceptionRoutedEventArgs>(img_ImageFailed); } } }