WPF ComboBox TemplateBinding to selected value
- by Greg R
I'm trying to create an editable textbox via a drop down of selected values. Basically in Red Only mode I want the drop down to be a disabled textbox. It works fine when I do this with SelectedValue but when I need it to display the dropdown text and not the value. This is what I have:
<Style x:Key="EditableDropDownValueOnly" TargetType="ComboBox">
<Setter Property="Width" Value="Auto" />
<Setter Property="FontSize" Value="11" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="FontFamily" Value="Verdana" />
<Setter Property="MinWidth" Value="25" />
<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>
SelectedItem is a KeyValuePair, since my drop down is bound to a dictionary. I'm trying to display the "Value" element in my template. Is that possible? Thanks a lot!