private void ListView_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(ApplicationInfo))) { CairoLogger.Instance.Debug(e.Data.GetData(typeof(ApplicationInfo)).ToString()); ApplicationInfo dropData = e.Data.GetData(typeof(ApplicationInfo)) as ApplicationInfo; ListView dropTarget = sender as ListView; if (dropTarget.ItemsSource is Category) { Category target = dropTarget.ItemsSource as Category; if (target.Type == AppCategoryType.QuickLaunch) { e.Effects = DragDropEffects.Copy; // Do not duplicate entries if (!target.Contains(dropData)) { ApplicationInfo dropClone = dropData.Clone(); if (e.OriginalSource != null && e.OriginalSource is FrameworkElement && (e.OriginalSource as FrameworkElement).DataContext != null && (e.OriginalSource as FrameworkElement).DataContext is ApplicationInfo) { target.Insert(target.IndexOf((e.OriginalSource as FrameworkElement).DataContext as ApplicationInfo), dropClone); } else { target.Add(dropClone); } dropClone.Icon = null; // icon may differ depending on category dropClone.IconPath = null; } else { // reorder existing if (e.OriginalSource != null && e.OriginalSource is FrameworkElement && (e.OriginalSource as FrameworkElement).DataContext != null && (e.OriginalSource as FrameworkElement).DataContext is ApplicationInfo) { target.Move(target.IndexOf(dropData), target.IndexOf((e.OriginalSource as FrameworkElement).DataContext as ApplicationInfo)); } } } else if (sourceView != null && sourceView != sender) { e.Effects = DragDropEffects.Move; Category source = sourceView.ItemsSource as Category; source.Remove(dropData); if (source.Type != AppCategoryType.QuickLaunch) { target.Add(dropData); // if coming from quick launch, simply remove from quick launch } } } else { e.Effects = DragDropEffects.Move; (sourceView.ItemsSource as IList <ApplicationInfo>).Remove(dropData); (dropTarget.ItemsSource as IList <ApplicationInfo>).Add(dropData); } } else if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] fileNames = e.Data.GetData(DataFormats.FileDrop) as string[]; if (fileNames != null) { ListView dropTarget = sender as ListView; if (!(dropTarget.ItemsSource is Category)) { foreach (String fileName in fileNames) { CairoLogger.Instance.Debug(fileName); if (Shell.Exists(fileName)) { ApplicationInfo customApp = AppGrabber.PathToApp(fileName, false); if (!object.ReferenceEquals(customApp, null)) { (dropTarget.ItemsSource as IList <ApplicationInfo>).Add(customApp); if (dropTarget.Items.Contains(customApp)) { dropTarget.ScrollIntoView(dropTarget.Items[dropTarget.Items.IndexOf(customApp)]); } } } } } } } sourceView = null; isDragging = false; }