Select text from combobox

坚强是说给别人听的谎言 提交于 2019-12-24 19:17:15

问题


I have a simple question:

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>

How can i do that without using code behind or putting a lame button next to it?


回答1:


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.



来源:https://stackoverflow.com/questions/8259245/select-text-from-combobox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!