![](/img/trans.png)
[英]WPF: Drag and drop a file into the whole window (titlebar and window borders included)
[英]Drag and Drop file transfer in WPF. How to get file name of the dropped content in a window
我正在创建一个本地文件传输应用程序。 我希望用户将项目拖放到文件传输应用程序中以启动文件传输,就像skype或其他信使一样。
丢弃一个项目。 丢弃事件已触发。 但是,我不知道从哪里获取项目的详细信息,例如位置,大小等,例如,如果我放下图像。 我想阅读上面提到的细节。
注意:我已启用AllowDrop
&Subsribed to Drop
事件。[如果有帮助]
你的意思是文件大小或像素大小? 无论如何,使用此代码:
private void Window_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, true))
{
string[] droppedFilePaths = e.Data.GetData(DataFormats.FileDrop, true) as string[];
foreach (var path in droppedFilePaths)
{
string location = null;
int pxWidth = 0, pxHeight = 0;
FileInfo fi = new FileInfo(path);
//fi.Length //File size
//fi.DirectoryName //Directory
using (var fs = fi.OpenRead())
{
try
{
var bmpFrame = BitmapFrame.Create(fs);
var m = bmpFrame.Metadata as BitmapMetadata;
if (m != null)
location = m.Location;
pxWidth = bmpFrame.PixelWidth;
pxHeight = bmpFrame.PixelHeight;
}
catch
{
//File isn't image
}
}
this.fileList.Items.Add(string.Format("({0}x{1}), location: {2}", pxWidth, pxHeight, location));
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.