如何在我的用户控件中接受剪贴板中的粘贴?
我有一个 UserControl,奇怪的是,它将一堆其他控件和逻辑捆绑到一个整洁的小包中。它有一个 Text 属性,它接受一个字符串并执行魔法,为用户显示结果。惊人的。
我从文本框中获取该文本。用户将剪贴板中的文本粘贴到文本框中,该文本框绑定到我的 UserControl 上的 DP。
我想做的是去掉中间人并接受我的用户控件中的粘贴。
我已经尝试过使用 DataObject.Pasting 附加事件,但这似乎不起作用。
你怎么做?
用我当前的解决方案回答了我自己的问题,但老实说它“闻起来”。如果有人有更好的答案,请添加它,如果它有效并且更好,我会选择它。
I've got a UserControl that, oddly enough, bundles a bunch of other controls and logic into a tidy little package. It has a Text property that accepts a string
and does magic, displaying the results for the user. Awesome.
I get that text from a TextBox. The user pastes text from the clipboard in the textbox, which is bound to a DP on my UserControl.
What I'd like to do is cut out the middle man and accept pastes within my UserControl.
I've already tried using the DataObject.Pasting attached event, but that appears not to work.
How do you do it?
Answered my own question with my current solution, but honestly it "smells". If anybody has a better answer, please add it and if it works and is better I'll select it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的大脑开火了。 命令绑定。现在我知道何时有人尝试粘贴并可以从那里取出它。
XAML:(
请原谅错误的代码;现在尝试让它工作)和事件处理程序:
这闻起来,恕我直言。但我不知道还能如何处理这个问题。
My brain fired. Command Bindings. Now I know when someone tries to paste and can take it from there.
XAML:
(excuse the bad code; trying to get this working for now) And the event handler:
This smells, IMHO. But I'm not sure how else to handle this.