示例#1
0
        private void CreateDragDropWindow(Visual dragElement)
        {
            Debug.Assert(this.dragdropWindow == null);

            this.dragdropWindow = new Window();

            this.dragdropWindow.WindowStyle        = WindowStyle.None;
            this.dragdropWindow.AllowsTransparency = true;
            this.dragdropWindow.AllowDrop          = false;
            this.dragdropWindow.Background         = null;
            this.dragdropWindow.IsHitTestVisible   = false;
            this.dragdropWindow.SizeToContent      = SizeToContent.WidthAndHeight;
            this.dragdropWindow.Topmost            = true;
            this.dragdropWindow.ShowInTaskbar      = false;

            this.dragdropWindow.SourceInitialized += new EventHandler(
                delegate(object sender, EventArgs args)
            {
                //TODO assert that we can do this..
                PresentationSource windowSource = PresentationSource.FromVisual(this.dragdropWindow);
                IntPtr handle = ((HwndSource)windowSource).Handle;

                Int32 styles = Win32Interop.GetWindowLong(handle, Win32Interop.GWL_EXSTYLE);

                Win32Interop.SetWindowLong(handle, Win32Interop.GWL_EXSTYLE, styles | Win32Interop.WS_EX_LAYERED | Win32Interop.WS_EX_TRANSPARENT);
            });

            Rectangle r = new Rectangle();

            r.Width  = ((FrameworkElement)dragElement).ActualWidth;
            r.Height = ((FrameworkElement)dragElement).ActualHeight;
            r.Fill   = new VisualBrush(dragElement);

            this.dragdropWindow.Content = r;

            // we want QueryContinueDrag notification so we can update the window position
            //DragDrop.AddPreviewQueryContinueDragHandler(source, QueryContinueDrag);

            // put the window in the right place to start
            this.UpdateWindowLocation();
        }