博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WP7 剪贴板 Clipboard
阅读量:6125 次
发布时间:2019-06-21

本文共 1801 字,大约阅读时间需要 6 分钟。

偶然需要在应用中访问剪贴板,其实和SL访问剪贴板是一样的。

参考下MSDN:

写得清楚明白:

Clipboard Class

System.Windows.Clipboard

Namespace:

Assembly: System.Windows (in System.Windows.dll)

 

有三个方法:

Public methodStatic memberSupported by Silverlight for Windows Phone

Queries the clipboard for the presence of data in the UnicodeText format.

Public methodStatic memberSupported by Silverlight for Windows Phone

Retrieves Unicode text data from the system clipboard, if Unicode text data exists.

Public methodStatic memberSupported by Silverlight for Windows Phone

Sets Unicode text data to store on the clipboard, for later access with .

 

看名字就能知道用法了额

ContainsText返回值是bool型,用于查看Clipboard是否有内容

GetText 是从Clipboard取值

SetText 是往Clipboard赋值

 

不过要注意GetText 和SetText 可能会引起SecurityException哦

参见MSDN:和

 

GetText SecurityException:

Invoked this method from outside a user-initiated context.

Clipboard access user dialog box was not confirmed.

Invoked this method in a Windows Phone application.

 

SetText SecurityException:

Invoked this method from outside a user-initiated context.

Clipboard access user dialog box was not confirmed.

 

 

Under partial trust (the default mode), Silverlight restricts clipboard access to its two key APIs: and SetText. These APIs can only be invoked from within a context that is determined by the Silverlight runtime to be in response to a user-initiated action. For example, clipboard access is valid from within a handler for a or event. For examples of situations that are not considered user-initiated, clipboard access is not valid from a handler for or from a constructor. Clipboard access under partial trust also requires the user to confirm access through completion of a Silverlight access-confirmation dialog box.

If you specifically produce an out-of-browser application and request elevated trust, this security restriction on the API and its dialog box are not used. For more information, see .

 

 

简单说就是GetTextSetText 在Click 或 KeyDown事件中是被允许的,在 Loaded事件或构造函数中是被禁止访问的。

在使用的时候要注意额…

 

(PS:试了下在WP里SetText 是可以在Loaded使用,而GetText会报异常)

转载地址:http://ozbua.baihongyu.com/

你可能感兴趣的文章
Spring Boot 整合Spring Security 和Swagger2 遇到的问题小结
查看>>
[20170628]12C ORA-54032.txt
查看>>
除以2
查看>>
高可用集群原理解析
查看>>
Nginx配置URL转向tomcat
查看>>
极客Web前端开发资源大荟萃#001
查看>>
让div固定在某个位置
查看>>
Java开发环境Docker镜像
查看>>
从无到有,WebService Apache Axis2初步实践
查看>>
任务调度(一)——jdk自带的Timer
查看>>
UIKit框架(15)PCH头文件
查看>>
整理看到的好的文档
查看>>
Linux磁盘管理和文件系统管理
查看>>
linux运维人员的成功面试总结案例分享
查看>>
Windows DHCP Server基于MAC地址过滤客户端请求实现IP地址的分配
查看>>
命令查询每个文件文件数
查看>>
《跟阿铭学Linux》第8章 文档的压缩与打包:课后习题与答案
查看>>
RAC表决磁盘管理和维护
查看>>
HDU 3622 Bomb Game(二分+2-SAT)
查看>>
Apache通过mod_php5支持PHP
查看>>