简体   繁体   English

当应用程序在锁屏Windows Phone 8下运行时,ClipBoard.SetText引发异常

[英]ClipBoard.SetText throws exception when application is running under lock screen Windows phone 8

I'm building a Windows Phone application which will allow the user to set text remotely even when the application is running under lockscreen. 我正在构建一个Windows Phone应用程序,即使该应用程序在锁定屏幕下运行,该应用程序也允许用户远程设置文本。

When I called ClipBoard.SetText("some data") when the application was under lock screen, it threw the following exception: 当我在锁定屏幕下调用ClipBoard.SetText("some data")时,它引发了以下异常:

at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.Clipboard_SetText(String text)
at System.Windows.Clipboard.SetText(String text)
...

Any suggestion or workaround for this issue? 对这个问题有什么建议或解决方法吗?

According to [msdn] 1 The Clipboard.SetText Method is restricted to the usage of a user-initiated action only. 根据[msdn] 1 ,Clipboard.SetText方法仅限于用户启动的操作的使用。 Therefore i would not expect .SetText to work in a locked mode. 因此,我不希望.SetText在锁定模式下工作。

Well as a App User this makes sense . 作为应用程序用户, 这很有意义 I wouldn't wan't a app messing around with my clipboard while i'm not using the app. 当我不使用应用程序时,我不会希望该应用程序在剪贴板上乱七八糟。 Say, I copy a number and by the time i want to paste the number another app replaced the number with another text.... 说,我复制一个数字,等到我想粘贴该数字时,另一个应用程序用另一个文本替换了该数字。

Copied from Remarks: ... 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. 从备注复制:...这些API只能在Silverlight运行时确定为响应用户启动的操作的上下文中调用。 For example, clipboard access is valid from within a handler for a Click or KeyDown event. 例如,剪贴板访问在处理程序内对于Click或KeyDown事件有效。 For examples of situations that are not considered user-initiated, clipboard access is not valid from a handler for Loaded or from a constructor. 对于某些情况,例如不是由用户启动的情况,剪贴板访问对于Loaded的处理程序或构造函数无效。

What about: The App persists the text in a temporary store (persisting setting or variable instance) and updates the Clipboard whenever the user returns to the app? 关于什么:应用程序将文本保留在临时存储区中(持久设置或变量实例),并在用户返回到应用程序时更新剪贴板?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM