How to display combo box as textbox in WPF via a style template trigger?

Posted by Greg R on Stack Overflow See other posts from Stack Overflow or by Greg R
Published on 2010-03-19T19:07:50Z Indexed on 2010/03/19 19:11 UTC
Read the original article Hit count: 256

Filed under:
|

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!

© Stack Overflow or respective owner

Related posts about wpf

Related posts about wpf-triggers