Ejemplo n.º 1
0
        private static void OnDrop(object _sender, DragEventArgs _dragEventArgs)
        {
            DependencyObject d = _sender as DependencyObject;

            if (d == null)
            {
                return;
            }
            Object          target     = d.GetValue(DragDropTargetProperty);
            IDragDropTarget dropTarget = target as IDragDropTarget;

            if (dropTarget != null)
            {
                if (_dragEventArgs.Data.GetDataPresent(DataFormats.Html))
                {
                    dropTarget.OnHtmlDrop((object)_dragEventArgs.Data.GetData(DataFormats.Html));
                }
                else if (_dragEventArgs.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    dropTarget.OnFileDrop((string[])_dragEventArgs.Data.GetData(DataFormats.FileDrop));
                }
            }
            else
            {
                throw new Exception("DragDropTarget object must be of type IDragDropTarget");
            }
        }
Ejemplo n.º 2
0
        private static void OnDrop(object _sender, DragEventArgs _dragEventArgs)
        {
            if (!(_sender is DependencyObject d))
            {
                return;
            }
            object          target     = d.GetValue(FileDragDropTargetProperty);
            IDragDropTarget fileTarget = target as IDragDropTarget;

            if (fileTarget != null)
            {
                if (_dragEventArgs.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    fileTarget.OnFileDrop((string[])_dragEventArgs.Data.GetData(DataFormats.FileDrop));
                }
                else if (_dragEventArgs.Data.GetDataPresent(DataFormats.Text))
                {
                    fileTarget.OnTextDrop((string)_dragEventArgs.Data.GetData(DataFormats.Text));
                }
            }
            else
            {
                throw new Exception("FileDragDropTarget object must be of type IFileDragDropTarget");
            }
        }