tags:

views:

425

answers:

1

I created a FlatCombo Style that I want to apply to a combo box. The one thing that does not work the way that I want is when the ComboBox has focus. I want almost no indication that it has focus. Currently there is a blue highlight on the text area. I assume this is being picked up from my 3rd party resource dictionary. How do I adjust my local style so all it shows on focus is a light dashed line?

Thanks,

Dave

<UserControl.Resources>

    <Style x:Key="MyFocusVisual">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate>
                    <Rectangle Margin="-1" StrokeThickness="1" Stroke="Black" StrokeDashArray="1 2"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ControlTemplate x:Key="FlatCombo" TargetType="{x:Type ComboBox}">
    <ContentControl            
        Content="{TemplateBinding SelectionBoxItem}"            
        ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"            
        ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"            
        Margin="0,0,0,0"  Focusable="True"

        />
</ControlTemplate>

<Style TargetType="{x:Type ComboBox}" x:Key="DropDown">
    <Setter Property="OverridesDefaultStyle" Value="False" />
    <Style.Triggers>
        <MultiTrigger>
            <MultiTrigger.Conditions>
                <Condition Property="IsMouseOver" Value="False" />
                <Condition Property="IsFocused" Value="False"/>
            </MultiTrigger.Conditions>
            <Setter Property="Template" Value="{StaticResource FlatCombo}" />
        </MultiTrigger>
    </Style.Triggers>
</Style>

        <ComboBox IsSynchronizedWithCurrentItem="True" x:Name="ComboBoxMinute" Width="Auto" 
              Height="Auto" HorizontalAlignment="Center" 
              Background="{Binding Path=Background, ElementName=TextBlockDate, Mode=Default}" 
              BorderBrush="{x:Null}" FontFamily="{Binding Path=FontFamily, 
              ElementName=TextBlockDate, Mode=Default}" 
              FontSize="{Binding Path=FontSize, ElementName=TextBlockDate, Mode=Default}" 
              Foreground="{Binding Path=Foreground, ElementName=TextBlockDate, Mode=Default}" 
              Padding="0,0,0,0" MaxDropDownHeight="200" Style="{StaticResource DropDown}" VerticalContentAlignment="Stretch" 
              VerticalAlignment="Center" FocusVisualStyle="{DynamicResource MyFocusVisual}"/>
+1  A: 

You should set OverridesDefaultStyle to True, rather than false. You are completely replacing the control, so it's all going to be replaced.

However, looking at your code, you say you want it to be flat when focused; yet your triggers are going to only the flat control template when the control is not focused, and the mouse is not over it. Is that what you want?

Another aspect to consider here, is that the text box in the case of an editable combo will have the text highlight in blue, which is something I believe can't be changed currently.

dhopton