How to display combo box as textbox in WPF via a style template trigger?
- by Greg R
I would like to display a combobox drop down list as a textbox when it's set to be read only. For some reason I can't seem to bind the text of the selected item in the combo box to the textbox. This is my XAML:
<Style x:Key="EditableDropDown" TargetType="ComboBox">
<Style.Triggers>
<Trigger Property="IsReadOnly" Value="True">
<Setter Property="Background" Value="#FFFFFF" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<TextBox Text="{TemplateBinding SelectedItem, Converter={StaticResource StringCaseConverter}}"
BorderThickness="0"
Background="Transparent"
FontSize="{TemplateBinding FontSize}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
FontFamily="{TemplateBinding FontFamily}"
Width="{TemplateBinding Width}"
TextWrapping="Wrap"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
<ComboBox IsReadOnly="{Binding ReadOnlyMode}" Style="{StaticResource EditableDropDown}" Margin="0 0 10 0">
<ComboBoxItem IsSelected="True">Test</ComboBoxItem>
</ComboBox>
When I do this, I get the following as the text:
System.Windows.Controls.ComboBoxItem: Test
I would really appreciate the help!