WPF combobox loses Aero theme when using a style trigger

Posted by Greg R on Stack Overflow See other posts from Stack Overflow or by Greg R
Published on 2010-03-22T16:36:33Z Indexed on 2010/03/22 16:41 UTC
Read the original article Hit count: 895

Filed under:
|
|

I am using style triggers to change combo box to texbox if it's readonly, but for some reason when I apply the style, it cause the combobox theme to change from Aero to Windows Classic (the theme I currently have in use on my PC). Can I avoid this somehow? Here is my code:

<ComboBox ItemsSource="{Binding Source={StaticResource AllCountries}}" 
        SelectedValue="{Binding OrderInfoVm.BillingCountry}" DisplayMemberPath="Value" 
        SelectedValuePath="Key" IsReadOnly="{Binding ReadOnlyMode}" 
        Style="{StaticResource EditableDropDown}" />

<Style x:Key="EditableDropDown" TargetType="ComboBox">
        <Style.Triggers>
            <Trigger Property="IsReadOnly" Value="True">
                <Setter Property="SelectedValuePath" Value="Content" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ComboBox">
                            <TextBox Text="{TemplateBinding SelectedValue, 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>

© Stack Overflow or respective owner

Related posts about wpf

Related posts about combobox