<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c1="clr-namespace:C1.WPF.RichTextBox">

    <ControlTemplate x:Key="C1LengthTool.ComboBox" TargetType="ComboBox">
        <Grid>
            <Grid.Resources>
                <Style x:Key="comboToggleStyle" TargetType="ToggleButton">
                    <Setter Property="Foreground" Value="#FF333333"/>
                    <Setter Property="Background" Value="#FF1F3B53"/>
                    <Setter Property="BorderBrush">
                        <Setter.Value>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="#FFA3AEB9" Offset="0"/>
                                <GradientStop Color="#FF8399A9" Offset="0.375"/>
                                <GradientStop Color="#FF718597" Offset="0.375"/>
                                <GradientStop Color="#FF617584" Offset="1"/>
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="BorderThickness" Value="1"/>
                    <Setter Property="Padding" Value="3"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ToggleButton">
                                <Grid>
                                    <VisualStateManager.VisualStateGroups>
                                        <VisualStateGroup x:Name="CommonStates">
                                            <VisualState x:Name="Normal"/>
                                            <VisualState x:Name="MouseOver">
                                                <Storyboard>
                                                    <DoubleAnimation Duration="0" To="0.4" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundOverlay"/>
                                                </Storyboard>
                                            </VisualState>
                                            <VisualState x:Name="Pressed">
                                                <Storyboard>
                                                    <!--<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundOverlay"/>-->
                                                    <DoubleAnimation Duration="0" To="0.4" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Highlight"/>
                                                </Storyboard>
                                            </VisualState>
                                            <VisualState x:Name="Disabled"/>
                                        </VisualStateGroup>
                                        <VisualStateGroup x:Name="CheckStates">
                                            <VisualState x:Name="Checked">
                                                <Storyboard>
                                                    <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="BackgroundOverlay"/>
                                                    <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Highlight"/>
                                                </Storyboard>
                                            </VisualState>
                                            <VisualState x:Name="Unchecked"/>
                                        </VisualStateGroup>
                                        <VisualStateGroup x:Name="FocusStates">
                                            <VisualState x:Name="Focused"/>
                                            <VisualState x:Name="Unfocused"/>
                                        </VisualStateGroup>
                                    </VisualStateManager.VisualStateGroups>
                                    <Rectangle x:Name="Background" Fill="{TemplateBinding Background}"/>
                                    <!-- Stroke="{TemplateBinding BorderBrush}" StrokeThickness="{TemplateBinding BorderThickness}"-->
                                    <Rectangle x:Name="BackgroundOverlay" Fill="#FF6DBDD1" StrokeThickness="1" Opacity="0" />
                                    <Rectangle x:Name="Highlight" IsHitTestVisible="false" Opacity="0" Stroke="#FF6DBDD1" Fill="#FFF1F4F6" StrokeThickness="1"/>
                                    <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
                <c1:C1LengthUnitConverter x:Key="lengthUnitConverter"/>
            </Grid.Resources>
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal"/>
                    <VisualState x:Name="MouseOver"/>
                    <VisualState x:Name="Disabled"/>
                </VisualStateGroup>
                <VisualStateGroup x:Name="FocusStates">
                    <VisualState x:Name="Focused"/>
                    <VisualState x:Name="Unfocused"/>
                    <VisualState x:Name="FocusedDropDown">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Duration="00:00:00" Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PopupBorder">
                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
                <VisualStateGroup x:Name="ValidationStates">
                    <VisualState x:Name="Valid"/>
                    <VisualState x:Name="InvalidUnfocused"/>
                    <VisualState x:Name="InvalidFocused"/>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Border x:Name="ContentPresenterBorder">
                <Grid>
                    <ToggleButton x:Name="DropDownToggle" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Right" Margin="0" Style="{StaticResource comboToggleStyle}" VerticalAlignment="Stretch" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"/>
                    <ContentPresenter x:Name="ContentPresenter" HorizontalAlignment="Center" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding SelectionBoxItem, Converter={StaticResource lengthUnitConverter}}" IsHitTestVisible="False"/>
                </Grid>
            </Border>
            <Rectangle x:Name="FocusVisualElement" IsHitTestVisible="false" Margin="-5" Opacity="0" Stroke="#FF6DBDD1" StrokeThickness="1"/>
            <Popup x:Name="Popup" IsOpen="{TemplateBinding IsDropDownOpen}">
                <Border x:Name="PopupBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3" HorizontalAlignment="Stretch" Height="Auto">
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FFFFFFFF" Offset="0"/>
                            <GradientStop Color="#FFFEFEFE" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    <ScrollViewer x:Name="ScrollViewer" BorderThickness="0" Padding="1">
                        <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
                    </ScrollViewer>
                </Border>
            </Popup>
        </Grid>
    </ControlTemplate>
    
</ResourceDictionary>
