#708 – 将文件拖入到WPF应用程序中(Dragging a File Into a WPF Application)
来源:互联网 发布:怎么添加usb端口 编辑:程序博客网 时间:2024/06/12 11:04
原文地址:https://wpf.2000things.com/2012/12/10/708-dragging-a-file-into-a-wpf-application/
如果你的应用程序中允许将文件拖入,那么就需要使用DataFormats.FileDrop 类型的数据。
在代码中指定只允许FileDrop 类型的数据进入。
private void Window_DragEnter(object sender, DragEventArgs e){ if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effects = DragDropEffects.Copy; else e.Effects = DragDropEffects.None; e.Handled = true;} private void Window_DragOver(object sender, DragEventArgs e){ if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effects = DragDropEffects.Copy; else e.Effects = DragDropEffects.None; e.Handled = true;}
当你在Drop 事件处理函数中调用GetData 函数的时候,你会获得被拖入文件的文件名数组。下面是一个列子,在Label 上显示拖入文件的文件名并且用TextBlock 显示文件中的文本内容。
private void Window_Drop(object sender, DragEventArgs e){ string[] filenames = (string[])e.Data.GetData(DataFormats.FileDrop); lblFilename.Content = filenames[0]; txtContent.Text = File.ReadAllText(filenames[0]);}
0 0
- #708 – 将文件拖入到WPF应用程序中(Dragging a File Into a WPF Application)
- #707 – 从WPF程序中拖拽一个List列表的数据到Excel(Dragging a List of Items from a WPF Application into Excel)
- Localize a WPF application
- Creating A WPF Chat Client Server Application(一)
- Hosting Office in a WPF Application
- Showing a Splash Screen whilst initializing a WPF Prism application
- Beginning a WPF/MVVM application: Navigating between views
- WPF工程打开控制台并输出 Output to console from a WPF application
- WPF 4 Ribbon 开发 之 应用程序菜单(Application Menu)
- WPF实例学习(A-01)
- WPF实例学习(A-02)
- WPF实例学习(A-03)
- WPF实例学习(A-04)
- WPF实例学习(A-05)
- Saving a Canvas into a PNG file – WP8
- A Sortable ObservableCollection for WPF
- A Versatile TreeView for WPF
- WPF A股行情 软件界面
- HDU 1814:Peaceful Commission(2-SAT的字典序最小解)
- 超详细的vim+cscope 的使用规则 转载
- 静态多态和动态多态
- Cudnn安装详细步骤
- python itertools 模块完全掌握(1)
- #708 – 将文件拖入到WPF应用程序中(Dragging a File Into a WPF Application)
- HDU
- exp和expdp怎么保证数据的一致性?
- python upload file and form
- springmvc常用注解标签详解
- popupWindow 嵌套scrollview异常显示的原因.
- 半闲居士视觉SLAM十四讲笔记(4)李群与李代数
- AndroidStudio非法字符: '\ufeff'解决
- 运算符的优先级