WPF ComboBox TemplateBinding to selected value

Posted by Greg R on Stack Overflow See other posts from Stack Overflow or by Greg R
Published on 2010-04-02T14:41:33Z Indexed on 2010/04/02 14:43 UTC
Read the original article Hit count: 496

Filed under:
|
|

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!

© Stack Overflow or respective owner

Related posts about wpf

Related posts about combobox