我試圖通過拖放功能上傳文件。我成功地完成了UI工作,但是我無法訪問在後端放置的對象。如果我確實在代碼後面,我能夠成功地獲取對象,但我試圖採用MVVM方法。使用Caliburn拖放文件MVVM
AttachmentView.xaml
Cal:Message.Attach="[Drop] = [SaveFile($eventArgs)]"
AttachmentViewModel.cs
public virtual async void SaveFile(DragEventArgs e)
{
var fileStream = new FileStream([File name goes here], FileMode.Open, FileAccess.Read);
}
我已經試過EventArgs的,我無法找到該文件對象的屬性。代碼測試時,DragEventArgs爲null。背後代碼
AttachmentView.xaml.cs
private void ImagePanel_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
// Note that you can have more than one file.
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
// Assuming you have one file that you care about, pass it off to whatever
// handling code you have defined.
Upload(files);
}
}
不,但我只是想幫忙。我甚至在評論中這樣說,我沒有。你讀過我寫的嗎? –