public void ShowFit() { isChanged = true; BoardImageItem item = GetSelectItem(); if (item != null) { item.ShowFit(); } }
/// <summary> /// 添加图片 /// </summary> /// <param name="url"></param> public BoardImageItem Add(string fileName) { isChanged = true; Border border = new Border(); ImageBrush imageBrush = new ImageBrush(); FileStream img = new FileStream(fileName, FileMode.Open); byte[] imgbyte = new byte[img.Length]; img.Read(imgbyte, 0, imgbyte.Length); img.Close(); BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.StreamSource = new MemoryStream(imgbyte); bitmap.EndInit(); imageBrush.ImageSource = bitmap; imageBrush.Stretch = Stretch.UniformToFill; border.Background = imageBrush; border.Width = bitmap.Width; border.Height = bitmap.Height; border.IsManipulationEnabled = true; //动态事件 border.MouseDown += new MouseButtonEventHandler(border_MouseDown); border.MouseMove += new MouseEventHandler(border_MouseMove); border.MouseUp += new MouseButtonEventHandler(border_MouseUp); border.MouseWheel += new MouseWheelEventHandler(border_MouseWheel); //返回值 BoardImageItem item = new BoardImageItem(); item.BitmapImage = bitmap; item.FrameworkElement = border; this.BoardImageList.Add(item); this.touchPad.Children.Add(border); this.Select(item); item.ShowFit(); if (BoardImageList.Count == 1) { item.ShowCenter(); } return(item); }