如何让用户复制任意文本?

发布于 2024-11-24 17:47:32 字数 656 浏览 1 评论 0原文

我有一个应用程序,可以在其中生成文本(大约 500 个字符),并且我希望用户能够通过某种方式复制该文本以在应用程序外部使用。

我不想使用此应用程序的任何功能(例如网络或联系人)。

这是我尝试过的(以及失败的原因)

  • TextBox。只读 = true;全选();
    • 无法全选只读文本框
  • 关闭只读,隐藏SIP
    • 无法隐藏用户正在交互的(非只读)TextBox 上的 SIP(​​我希望用户能够复制,因此需要与控件交互)
  • 允许编辑、显示 sip、全选()
    • 除非用户选择选择文本,否则“复制”图标不会出现
  • On choicechanged (actuallychanged), SelectAll()
    • 除非用户选择文本,否则“复制”图标不会出现?复制图标出现不稳定,我认为这不是可接受的用户体验。

所以在这一点上,我距离我想要的用户体验还很远,而且我仍然没有任何有效的东西。有什么建议吗?

回答我的问题的其他一些可能的方法包括:

  • “如何强制复制按钮出现在我以编程方式选择的文本上方?”
  • “如何更改文本框中点击的选择行为?”

I have an app, where I generate text (about 500 characters), and I would like the user to have some means of copying that text for use outside of the application.

I don't want to use any capabilities for this app (like web, or contacts).

Here's what I've tried (and why it's failed)

  • TextBox. IsReadOnly = true; SelectAll();
    • Can't SelectAll a read only text box
  • Turn off read only, hide the SIP
    • Can't hide the SIP on a (non-read-only) TextBox that the user is interacting with (I want to enable the user to copy, so needs to interact with the control)
  • allow edits, show sip, SelectAll()
    • The "copy" icon doesn't appear unless the user chose to select text
  • On selection changed (actually changed), SelectAll()
    • The "copy" icon doesn't appear unless the user selected the text? The copy icon appears erratically, nothing I would call an acceptable user experience.

So at this point, I'm quite far from what I want in a user experience, and I still don't have anything that works. Any suggestions?

Some other possible ways to answer my question include:

  • "How do I force the copy button to appear above text I programatically selected?"
  • "How do I change the selection behavior of a tap in a text box?"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一梦等七年七年为一梦 2024-12-01 17:47:32

据我所知,Windows Phone 7 剪贴板有一些限制:

  • 只能在 TextBox 中使用,并且只能在用户希望的情况下复制文本
  • 文本仅保留到设备锁定为止。 剪贴板也会被擦除干净

如果您的设备被锁定,即使您尝试Clipboard.SetText方法,如果您在没有用户交互的情况下调用此方法,您将注意到SecurityException。这是为了控制用户数据,以便流氓应用程序无法复制无法识别的文本。

但你可以尝试 Matt Laceys WP7Clipboard。它将剪贴板内容保存在图像中,甚至可以复制位图。

Afaik there are some limitations to the Windows Phone 7 Clipboard:

  • Works only in TextBox and can only copy text upon users wish
  • Text is only kept until device gets locked. If your device gets locked, the clipboard will be wiped clean

Even if you try Clipboard.SetText Method, you will notice the SecurityException if you call this method without the users interaction. This is to keep the users data under control so that no rogue app can copy unrecognized Text.

But you could try Matt Laceys WP7Clipboard. It saves the clipboard content inside an image and can even copy bitmaps.

腹黑女流氓 2024-12-01 17:47:32

这是我最终得到的主要工作

    private void Export(StackPanel stacker)
    {
        var exportHeader = new TextBlock();
        exportHeader.Text = "Export";
        stacker.Children.Add(exportHeader);
        var exportBox = new TextBox();
        stacker.Children.Add(exportBox);
        //exportBox.IsReadOnly = true; // hides SIP, but causes an exception with SelectAll() (pre-Mango, I haven't tried on Mango yet)
        exportBox.FontSize = 1;
        exportBox.Text = textToExport;
        exportBox.GotFocus += new System.Windows.RoutedEventHandler((send, ev) =>
        {
            ((TextBox)send).SelectAll();
        });
        exportBox.Focus();
    }

显然,将字体大小设置为 1 会产生差异,也许是因为所有文本都可以同时显示在屏幕上?谁知道呢。

我接受了这个答案,因为没有其他人发布更好的解决方案。我希望有更好的解决方案。如果你能让 SIP 消失,那就太棒了。

Here's what I eventually got mostly working

    private void Export(StackPanel stacker)
    {
        var exportHeader = new TextBlock();
        exportHeader.Text = "Export";
        stacker.Children.Add(exportHeader);
        var exportBox = new TextBox();
        stacker.Children.Add(exportBox);
        //exportBox.IsReadOnly = true; // hides SIP, but causes an exception with SelectAll() (pre-Mango, I haven't tried on Mango yet)
        exportBox.FontSize = 1;
        exportBox.Text = textToExport;
        exportBox.GotFocus += new System.Windows.RoutedEventHandler((send, ev) =>
        {
            ((TextBox)send).SelectAll();
        });
        exportBox.Focus();
    }

Apparently, making the font size 1 makes the difference here, maybe because all of the text can appear on the screen at once? Who knows.

I accepted this answer, because no one else posted a better solution. I would appreciate a better solution. If you can get the SIP to go away, that would be awesome.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文