How can I use ComboBox (WPF) to allow copying text from it to the clipboard?

There is a ComboBox described like this:

<ComboBox ItemsSource="{Binding DatabaseItems}"
            SelectedItem="{Binding CurrentDatabaseItem}" Margin="0 3">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Name}"/>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

Everything works, but the text from the ComboBox itself cannot be selected and copied after selecting an item from the list. How to achieve this effect while maintaining the ban on manual text input in the ComboBox? Thanks!

 0

1 answers

The combination of the IsReadOnly="True" IsEditable="True" properties gives exactly the effect you need.

Yes, by the way, if you want to display in the elements just the value of a text property, then ItemTemplate there is no need to redefine, you can use DisplayMemberPath:

<ComboBox ItemsSource="{Binding Items}" DisplayMemberPath="Text"
          IsReadOnly="True" IsEditable="True"/>
 0
Author: Андрей NOP, 2019-08-14 11:19:18