コード例 #1
0
        /// <summary>
        /// Drop in slide show
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SlideshowImageList_Drop(object sender, DragEventArgs e)
        {
            if (slideshowImageList.IsEnabled)
            {
                //Get data that's being draged
                MediaData dragedMediaData;
                dragedMediaData = (ImageData)e.Data.GetData(typeof(ImageData));
                if (dragedMediaData == null)
                {
                    dragedMediaData = (VideoData)e.Data.GetData(typeof(VideoData));
                }
                // Get X location of mouse (only moving in X direction, not Y)
                double mouseX = e.GetPosition(this).X;
                // Set other x values
                double dragedX_Left  = double.NaN;
                double dragedX_Right = double.NaN;
                // Set values
                bool insertedBefore = false;
                bool move           = true;


                // If the draged card is in the slideshow, get location
                if (dragedMediaData.Id >= 0)
                {
                    UIElement uiElement =
                        (UIElement)slideshowImageList.ItemContainerGenerator.ContainerFromIndex(dragedMediaData.Order);
                    dragedX_Left  = uiElement.TranslatePoint(new System.Windows.Point(0, 0), this).X;
                    dragedX_Right = dragedX_Left + uiElement.RenderSize.Width;
                    // If mnote draged outsided extent of selected item, it's not being moved
                    if (mouseX > dragedX_Left && mouseX < dragedX_Right)
                    {
                        move = false;
                    }
                }

                // If being mode, we're going to find the location to drop in
                if (move)
                {
                    // Loop over cards
                    for (int i = 0; i < slideshowImages.Count; i++)
                    {
                        int thisID = slideshowImages[i].Id;
                        if (thisID != dragedMediaData.Id)
                        {
                            // Extent of
                            double    extentLeft  = double.NaN;
                            double    extentRight = double.NaN;
                            UIElement uiElement   = (UIElement)slideshowImageList.ItemContainerGenerator.ContainerFromIndex(slideshowImages[i].Order);
                            // If previous or next card was the draged imaged, use all extent
                            if ((slideshowImages[i].Order == dragedMediaData.Order + 1) || (slideshowImages[i].Order == dragedMediaData.Order - 1))
                            {
                                extentLeft  = uiElement.TranslatePoint(new System.Windows.Point(0, 0), this).X;
                                extentRight = extentLeft + uiElement.RenderSize.Width;
                            }
                            else
                            {
                                // Otherwise use mid to mid
                                if (double.IsNaN(extentRight))
                                {
                                    extentLeft = uiElement.TranslatePoint(new System.Windows.Point(0, 0), this).X;
                                }
                                else
                                {
                                    extentLeft = extentRight;
                                }
                                extentRight = uiElement.TranslatePoint(new System.Windows.Point(0, 0), this).X + +uiElement.RenderSize.Width / 2;
                            }
                            // If drop location is within extent, insert it here
                            if (mouseX > extentLeft && mouseX < extentRight)
                            {
                                insertedBefore = true;
                                // If draged from folder view, create
                                if (dragedMediaData.Id == -1)
                                {
                                    MediaData mediaData = NewMediaData(dragedMediaData, slideshowImages.Count, i, true);
                                    selectedSlideShow.Insert(i, mediaData);
                                }
                                else
                                {
                                    // Otherwise move current
                                    selectedSlideShow.Move(dragedMediaData.Order, i);
                                }
                                // Image has been inserted, break loop
                                i = slideshowImages.Count;
                            }
                        }
                    }
                    // If we move it to the end
                    if (!insertedBefore)
                    {
                        // If draged from folder view, create
                        if (dragedMediaData.Id == -1)
                        {
                            MediaData mediaData = NewMediaData(dragedMediaData, slideshowImages.Count, slideshowImages.Count, true);
                            selectedSlideShow.Add(mediaData);
                        }
                        else
                        {
                            // Otherwise move current
                            selectedSlideShow.Move(dragedMediaData.Order, slideshowImages.Count - 1);
                        }
                    }
                }
                // Reset order for each image
                selectedSlideShow.ReOrder();
                slideshowImages = selectedSlideShow.MediaData;
                slideshowImageList.ItemsSource = slideshowImages;
                slideshowImageList.Items.Refresh();
            }
            else
            {
                MessageBox.Show("Slideshow needs to be created first", "Error");
            }
        }