Closed lmuestak closed 2 years ago
@lmuestak I tried to reproduce this with the following code. But I don't see an issue here. Is there maybe some other code not working or an exception thrown?
public interface IDragDropHandler : IDragSource, IDropTarget
{
}
public class MainViewModel : ViewModelBase, IDragDropHandler
{
public void StartDrag(IDragInfo dragInfo)
{
GongSolutions.Wpf.DragDrop.DragDrop.DefaultDragHandler.StartDrag(dragInfo);
}
public bool CanStartDrag(IDragInfo dragInfo)
{
return GongSolutions.Wpf.DragDrop.DragDrop.DefaultDragHandler.CanStartDrag(dragInfo);
}
public void Dropped(IDropInfo dropInfo)
{
GongSolutions.Wpf.DragDrop.DragDrop.DefaultDragHandler.Dropped(dropInfo);
}
public void DragDropOperationFinished(DragDropEffects operationResult, IDragInfo dragInfo)
{
GongSolutions.Wpf.DragDrop.DragDrop.DefaultDragHandler.DragDropOperationFinished(operationResult, dragInfo);
}
public void DragCancelled()
{
}
public bool TryCatchOccurredException(Exception exception)
{
return false;
}
public void DragEnter(IDropInfo dropInfo)
{
GongSolutions.Wpf.DragDrop.DragDrop.DefaultDropHandler.DragEnter(dropInfo);
}
public void DragOver(IDropInfo dropInfo)
{
GongSolutions.Wpf.DragDrop.DragDrop.DefaultDropHandler.DragOver(dropInfo);
}
public void DragLeave(IDropInfo dropInfo)
{
GongSolutions.Wpf.DragDrop.DragDrop.DefaultDropHandler.DragLeave(dropInfo);
}
public void Drop(IDropInfo dropInfo)
{
GongSolutions.Wpf.DragDrop.DragDrop.DefaultDropHandler.Drop(dropInfo);
}
}
The binding is to the MainViewModel
<TreeView dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
dd:DragDrop.DragHandler="{Binding}"
dd:DragDrop.DropHandler="{Binding}"
dd:DragDrop.UseDefaultDragAdorner="True"
dd:DragDrop.UseDefaultEffectDataTemplate="True"
dd:DragDrop.SelectDroppedItems="True"
ItemsSource="{Binding Data.TreeCollection1}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
<TextBlock Margin="2" Text="{Binding Caption}" />
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
Hi @punker76,
Im not able to drag or drop when both are handlers are set (drag and drop adorners are not visible and not moving). And there is also not exception in code. My goal is to drag some items from the treeview or listview onto to windows explorer to copy them. if drophandler is set then im able drag and drop items between treeview/treeview treeview/listview or listview/listview.
unfortunetly, im sitting so long an that issue.
I've created a simple project to simulate a windows explorer here: DragDop Demo Can we change the code, so that I'm able to drag the folders my explorer somewhere to windows explorer or windows desktop?
Thanks in advance! Best regards
@lmuestak Thanks for the sample and clarifying the issue. If you want to do a file drop then you can use your own DataObject to set the SetFileDropList.
public void StartDrag(IDragInfo dragInfo)
{
// drag&drop inside the ListBox with control key
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
{
GongSolutions.Wpf.DragDrop.DragDrop.DefaultDragHandler.StartDrag(dragInfo);
}
else
{
var files = dragInfo.SourceItems.OfType<FileModel>().Select(f => f.File).ToArray();
var dataObject = new DataObject();
var sc = new System.Collections.Specialized.StringCollection();
sc.AddRange(files!);
dataObject.SetFileDropList(sc);
dragInfo.DataObject = dataObject;
dragInfo.Effects = DragDropEffects.Copy;
}
}
I have created a full sample where you can drop files on and drag files to the explorer.
Hi @punker76,
thank you so much for help. Unfortunetly the link to your full example is not available. https://github.com/punker76/gong-wpf-dragdrop-file-sample
Best regards
@lmuestak Sorry, it was private, it's now public.
Now, its available. Thanks a lot!
@lmuestak Can i close this issue now?
@punker76 Yes, thanks a lot!
Introduction I have the following interface which also implements the
IDropTarget
andIDragSource
.There is also a corresponding class called
FolderBrowserViewModel
which implements theIFolderBrowserViewModel
interface.The user control
FolderBrowserView
I'm using is containing aTreeView
element with the following configuration:The issue
If only one of the properties is set then the drag and drop seems to work.
or like
But if I set both properties then nothing works.
Any ideas what the problem is?