public WindowBase() { ControlHelper.SetOwnerWindow(this); this.WindowStartupLocation = this.Owner == null ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner; this.Style = this.FindResource("DefaultWindowStyle") as Style; //bind command this.CloseWindowCommand = new RoutedUICommand(); this.MaximizeWindowCommand = new RoutedUICommand(); this.MinimizeWindowCommand = new RoutedUICommand(); this.BindCommand(CloseWindowCommand, this.CloseCommand_Execute); this.BindCommand(MaximizeWindowCommand, this.MaxCommand_Execute); this.BindCommand(MinimizeWindowCommand, this.MinCommand_Execute); this.LeftMouseMoveWindowEnable = true; this.KeyEscColseWindowEnable = true; this.KeyDown += WindowBase_KeyDown; Win32Helper.SetWindowSizeHook(this); }
/// <summary> /// 从一个Bitmap创建ImageSource /// </summary> /// <param name="image">Bitmap对象</param> /// <returns></returns> public static ImageSource CreateImageSourceFromImage(Bitmap image) { if (image == null) { return(null); } try { IntPtr ptr = image.GetHbitmap(); BitmapSource bs = Imaging.CreateBitmapSourceFromHBitmap(ptr, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); if (!bs.IsFrozen && bs.CanFreeze) { bs.Freeze(); } image.Dispose(); Win32Helper.DeleteObject(ptr); return(bs); } catch (Exception) { return(null); } }