コード例 #1
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (e.LeftButton != MouseButtonState.Pressed)
            {
                this.dragStartPoint = null;
            }

            if (this.dragStartPoint.HasValue)
            {
                Point position = e.GetPosition(this);
                if ((SystemParameters.MinimumHorizontalDragDistance <=
                    Math.Abs((double)(position.X - this.dragStartPoint.Value.X))) ||
                    (SystemParameters.MinimumVerticalDragDistance <=
                    Math.Abs((double)(position.Y - this.dragStartPoint.Value.Y))))
                {

                    Image contentImg = this.Content as Image;
                    BitmapImage contentBitmapImg = contentImg.Source as BitmapImage;
                    DataObject dataObject = new DataObject("GRID_ITEM", contentImg);
                    dataObject.SetData("CLASS_ID", this.ClassId);

                    if (dataObject != null)
                    {
                        #if DEBUG
                            Console.WriteLine("ToolboxItem.OnMouseMove: GridItem sollte erstellt werden: " + dataObject.ToString());
                            Console.WriteLine("ToolboxItem.OnMouseMove: TBI.ClassID: " + this.ClassId.ToString());
                            Console.WriteLine("ToolboxItem.OnMouseMove: BitmapImage " + contentBitmapImg.ToString());
                        #endif
                        DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy);
                    }
                }
                e.Handled = true;
            }
        }