#706 – 在应用程序间拖拽进行控件复制(Dragging User Interface Elements Between Applications)
来源:互联网 发布:tomcat java options 编辑:程序博客网 时间:2024/05/19 12:38
原文地址:https://wpf.2000things.com/2012/12/06/706-dragging-user-interface-elements-between-applications/
你可以在两个应用程序间拖拽控件,这种情况下,你通过读取可视树XAML中,你想要拖拽的控件的那一部分作为数据。
下面是一个拖拽整个StackPanel (包括其字控件)到另外一个应用程序的例子。
在拖拽应用程序这边(Application1),我们使用一个XamlWriter 实例将XAML存储为一个string。
设置StackPanel 的事件和属性如下(必须设置背景色,原因详见Panel类及其子类只有在设置了背景色以后才会触发鼠标事件):
MouseLeftButtonDown="StackPanel_MouseLeftButtonDown" Background="Transparent"
拖拽代码如下:
private void StackPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e){ string xaml = XamlWriter.Save(e.Source); DataObject data = new DataObject(DataFormats.Xaml, xaml); DragDrop.DoDragDrop((DependencyObject)e.Source, data, DragDropEffects.Copy);}
在放开接收一边(Application2),我们使用XamlReader 载入数据,并恢复为控件。设置Window 的Drop 事件响应函数。
private void Window_Drop(object sender, DragEventArgs e){ string xaml = (string)e.Data.GetData(DataFormats.Xaml); this.Content = XamlReader.Load(new XmlTextReader(new StringReader(xaml)));}
0 0
- #706 – 在应用程序间拖拽进行控件复制(Dragging User Interface Elements Between Applications)
- Creating Android Applications with HTML User Interface
- Design Patterns for User Interface for Mobile Applications
- dragging
- Interaction between services and applications at user level in Windows Vista
- #713 – 在拖拽操作中使用控件预览图作为鼠标(Setting the Cursor to an Image of an UIElement While Dragging)
- #708 – 将文件拖入到WPF应用程序中(Dragging a File Into a WPF Application)
- User Interface
- user interface
- Dragging rows between two different Flex DataGrid controls
- Oracle Applications Interface Programs
- Maximum Difference Between Two Elements
- 在linux中添加应用程序到applications列表
- Agile User Interface Development
- DTrace Graphical User Interface
- Using User-Interface Threads
- XML User Interface Language
- User Interface Freeze Milestone
- Fragment和Activity之间的通信
- 关于mysql中的count()函数
- Spring整合Ehcache管理缓存
- Android 6.0 以上实现状态栏白底黑字 「白色标题栏 App 享受 iOS 般的沉浸体验」
- PHP文件上传
- #706 – 在应用程序间拖拽进行控件复制(Dragging User Interface Elements Between Applications)
- WinHttpQueryDataAvailable的使用
- RSA加密算法原理及RES签名算法简介
- SHELL文件夹及其子文件夹的遍历
- 播放网络视频(可用)
- mysql几种性能测试的工具使用
- 设计模式
- shiro登录验证
- 简单的,到处是bug的,菜鸟自学初学写的,Java的银行存取款代码