从组合框中选择文本 [英] Select text from combobox
问题描述
我有一个简单的问题:
我在WPF中有一个组合框,但我希望用户能够将文本从其中复制到剪贴板.因此,选择所选项目的显示文本,然后右键单击copy或ctrl + c.就像默认的Windows行为一样.
I have a combobox in WPF, but i want users to be able to copy the text from it to the clipboard. So select the displayed text of the selected item and right-click copy or ctrl+c. Just like default windows behaviour.
<ComboBox
ItemsSource="{Binding Products}"
DisplayMemberPath="ProductName"
IsEditable="True"
SelectedItem="{Binding SelectedStroomProduct}">
</ComboBox>
如何在不使用代码的后面或旁边放置or脚的按钮的情况下做到这一点?
How can i do that without using code behind or putting a lame button next to it?
推荐答案
除非您采取特殊措施以吞下鼠标单击事件和键盘输入事件,否则可编辑组合框中的文本框将支持带有剪贴板命令(包括加速键快捷方式)的上下文菜单如 Ctrl + C .因此,基本上简单地将< ComboBox>
放在具有 IsEditable ="True"
的WPF窗口上就不会表现出您描述的行为.
Unless you do something special to swallow mouse click events and keyboard input events the text box inside the editable combo box will support a context menu with clipboard commands including accelerator shortcuts like Ctrl+C. So basically simply putting a <ComboBox>
on a WPF window having IsEditable="True"
does not exhibit the behavior you describe.
这篇关于从组合框中选择文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!