开发者

Web browser to WPF image drag and drop

I have a window set to allow drop and my Drop Event Handler is working fine for images dragged in from Wind开发者_高级运维ows Explorer. But dragging in pictures from a web browser has some quirks.

In Firefox, I am only getting .bmp files with random names. Images from IE 8 (haven't tested others) only show a Not Allowed mouse cursor. I guess this is because IE has a security prompt when dragging images out into the Windows Explorer.

Has anyone come across a solution, perhaps browser-agnostic, for dragging images out of a web browser and into a WPF window?

Here's the current event handler:

private void Window_Drop(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {
            string[] droppedFilePaths = e.Data.GetData(DataFormats.FileDrop, true) as string[];

            foreach (string droppedFilePath in droppedFilePaths)
            {
                Debug.WriteLine(droppedFilePath);
            }
        }
    }


I've just stumbled on this problem with IE8. Can't waste time figuring it out right now, but setting the window's PreviewDragEnter and PreviewDragOver to the following handler seems to work around the "Not Allowed" cursor part of it at the moment:

    private void Window_PreviewDragEnterAndOver ( object sender , DragEventArgs e ) {
        e.Effects = DragDropEffects.Link;
        e.Handled = true;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜