2013-02-12 13 views
1

我試圖設置一個WPF窗口,以便它可以通過Drag and Drop接受不同類型的數據。如果我提出一個新的項目和窗口設置爲以下:無法將文本拖動到WPF窗口中

<Window x:Class="DropShare.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="Window1" Height="300" Width="300" AllowDrop="True" DragEnter="Window_DragEnter"> 

    <Grid> 

    </Grid> 
</Window> 

,並設置代碼隱藏於:

public partial class Window1 : Window 
{ 
    public Window1() 
    { 
     InitializeComponent(); 
    } 

    private void Window_DragEnter(object sender, DragEventArgs e) 
    { 

    } 
} 

我只得到DragEnter燒製的文件。它從來沒有火其他 - 文字,圖像等

有什麼我失蹤了嗎?我讀過的所有教程都似乎暗示這是所需要的,因爲DragEnter事件處理程序讓我說出我接受的內容。

回答

1

所以,你的代碼工作正常,我下降。不過,試試這個...

在窗口:

<Label Background="Purple" HorizontalAlignment="Center" VerticalAlignment="Center" Content="Drag from here!" MouseDown="Label_MouseDown"/> 

並在後面的代碼:

private void Label_MouseDown(object sender, MouseButtonEventArgs e) 
{ 
    DragDrop.DoDragDrop(this, "This is just a test", DragDropEffects.All); 
} 

然後從標籤拖動到窗口,看看你的事件觸發。

如果這可行,它可能與Visual Studio和外部環境(可能)之間的權限級別有關。

參見:

https://superuser.com/questions/59051/drag-and-drop-file-into-application-under-run-as-administrator

+0

這確實奏效。 它似乎是一個權限的東西。我能夠從Chrome中拖動東西,但IE10沒有。我將使用Silverlight,因爲它似乎適用於一切。 – 2013-02-18 14:17:38

0

在WPF拖放功能總是有應對DragDrop類,請檢查here怎麼辦阻力和跨應用程序

+0

謝謝,但是這更多的** **開始一拖我的應用程序中的拖放操作。 – 2013-02-17 22:52:54