<ComboBox x:Class="HavenSoft.HexManiac.WPF.Controls.AngleComboBox"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:hsg3hv="clr-namespace:HavenSoft.HexManiac.WPF.Controls">
   <ComboBox.Resources>
      <ControlTemplate x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
         <Border x:Name="Border"
               Background="{TemplateBinding Background}"
               BorderBrush="{TemplateBinding BorderBrush}"
               BorderThickness="0,1">
            <Path x:Name="Arrow" Width="8"
               Fill="{DynamicResource Secondary}"
               VerticalAlignment="Center"
               HorizontalAlignment="Right"
               Data="M0,0 L0,2 L4,6 L8,2 L8,0 L4,4 z" />
         </Border>
      </ControlTemplate>
      <ControlTemplate x:Key="ComboBoxTextBox" TargetType="{x:Type TextBox}">
         <ScrollViewer x:Name="PART_ContentHost" Focusable="False" Background="{TemplateBinding Background}" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
      </ControlTemplate>
   </ComboBox.Resources>
   <ComboBox.Style>
      <Style TargetType="{x:Type hsg3hv:AngleComboBox}">
         <Setter Property="BorderBrush" Value="{DynamicResource Secondary}"/>
         <Setter Property="SnapsToDevicePixels" Value="true"/>
         <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
         <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
         <Setter Property="MinHeight" Value="18"/>
         <Setter Property="Background" Value="{DynamicResource Backlight}"/>
         <Setter Property="Foreground" Value="{DynamicResource Primary}"/>
         <Setter Property="Template">
            <Setter.Value>
               <ControlTemplate TargetType="{x:Type hsg3hv:AngleComboBox}">
                  <Grid>
                     <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                     </Grid.ColumnDefinitions>
                     <Path Name="LeftEdge" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" Grid.Column="0"
                           Width="6" StrokeThickness="1" Margin="0,0,-1,0" Stretch="Fill" SnapsToDevicePixels="True">
                        <Path.Data>
                           <PathGeometry>
                              <PathGeometry.Figures>
                                 <PathFigureCollection>
                                    <PathFigure StartPoint="1,0">
                                       <LineSegment Point="{Binding LeftTop, RelativeSource={RelativeSource TemplatedParent}}" />
                                       <LineSegment Point="{Binding LeftMiddle, RelativeSource={RelativeSource TemplatedParent}}" />
                                       <LineSegment Point="{Binding LeftBottom, RelativeSource={RelativeSource TemplatedParent}}" />
                                       <LineSegment Point="1,10"/>
                                    </PathFigure>
                                 </PathFigureCollection>
                              </PathGeometry.Figures>
                           </PathGeometry>
                        </Path.Data>
                     </Path>
                     <Path Name="RightEdge" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" Grid.Column="2"
                           Width="6" StrokeThickness="1" Margin="-1,0,0,0" Stretch="Fill" SnapsToDevicePixels="True">
                        <Path.Data>
                           <PathGeometry>
                              <PathGeometry.Figures>
                                 <PathFigureCollection>
                                    <PathFigure StartPoint="-1,0">
                                       <LineSegment Point="{Binding RightTop, RelativeSource={RelativeSource TemplatedParent}}" />
                                       <LineSegment Point="{Binding RightMiddle, RelativeSource={RelativeSource TemplatedParent}}" />
                                       <LineSegment Point="{Binding RightBottom, RelativeSource={RelativeSource TemplatedParent}}" />
                                       <LineSegment Point="-1,10"/>
                                    </PathFigure>
                                 </PathFigureCollection>
                              </PathGeometry.Figures>
                           </PathGeometry>
                        </Path.Data>
                     </Path>
                     <ToggleButton
                            Grid.Column="1"
                            Name="ToggleButton"
                            Template="{StaticResource ComboBoxToggleButton}"
                            Background="{DynamicResource Backlight}"
                            BorderBrush="{DynamicResource Secondary}"
                            Focusable="false"
                            IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                            ClickMode="Press">
                     </ToggleButton>
                     <ContentPresenter Name="ContentSite" IsHitTestVisible="False" Content="{TemplateBinding SelectionBoxItem}"
                            Grid.Column="1"
                            ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                            ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                            Margin="0,0,10,0"
                            VerticalAlignment="Center"
                            HorizontalAlignment="Left" />
                     <TextBox x:Name="PART_EditableTextBox"
                            Grid.Column="1"
                            Style="{x:Null}"
                            Template="{StaticResource ComboBoxTextBox}"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            Margin="0,0,10,0"
                            Focusable="True"
                            Background="{DynamicResource Backlight}"
                            Foreground="{DynamicResource Primary}"
                            Visibility="Hidden"
                            IsReadOnly="{TemplateBinding IsReadOnly}">
                        <TextBox.ContextMenu>
                           <ContextMenu>
                              <MenuItem Command="ApplicationCommands.Cut" />
                              <MenuItem Command="ApplicationCommands.Copy" />
                              <MenuItem Command="ApplicationCommands.Paste" />
                           </ContextMenu>
                        </TextBox.ContextMenu>
                     </TextBox>
                     <Popup
                            Grid.Column="1"
                            Name="Popup"
                            Placement="Bottom"
                            IsOpen="{TemplateBinding IsDropDownOpen}"
                            AllowsTransparency="True"
                            Focusable="False"
                            PopupAnimation="Slide">

                        <Grid Name="DropDown"
                              SnapsToDevicePixels="True"
                              MinWidth="{TemplateBinding ActualWidth}"
                              MaxHeight="{TemplateBinding MaxDropDownHeight}">
                           <Border
                                x:Name="DropDownBorder"
                                Background="{DynamicResource Background}"
                                BorderThickness="1"
                                BorderBrush="{DynamicResource Secondary}"/>
                           <ScrollViewer Margin="4,6" SnapsToDevicePixels="True">
                              <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                           </ScrollViewer>
                        </Grid>
                     </Popup>
                  </Grid>
                  <ControlTemplate.Triggers>
                     <Trigger Property="HasItems" Value="false">
                        <Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
                     </Trigger>
                     <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Foreground" Value="{DynamicResource Secondary}"/>
                     </Trigger>
                     <Trigger Property="HasOverflow" Value="True">
                        <Setter Property="ToolTip" Value="{Binding DisplayText}" />
                     </Trigger>
                     <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true">
                        <Setter TargetName="DropDownBorder" Property="CornerRadius" Value="0"/>
                        <Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
                     </Trigger>
                     <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="BorderBrush" Value="{DynamicResource Accent}"/>
                        <Setter TargetName="ToggleButton" Property="BorderBrush" Value="{DynamicResource Accent}"/>
                     </Trigger>
                     <Trigger Property="IsKeyboardFocusWithin" Value="True">
                        <Setter Property="BorderBrush" Value="{DynamicResource Accent}"/>
                        <Setter TargetName="ToggleButton" Property="BorderBrush" Value="{DynamicResource Accent}"/>
                     </Trigger>
                     <Trigger Property="IsEditable"  Value="true">
                        <Setter Property="IsTabStop" Value="false"/>
                        <Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible"/>
                        <Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/>
                     </Trigger>
                     <Trigger Property="Direction" Value="None">
                        <Setter TargetName="LeftEdge" Property="Width" Value="2"/>
                        <Setter TargetName="RightEdge" Property="Width" Value="2"/>
                     </Trigger>
                     <Trigger Property="Direction" Value="Left">
                        <Setter Property="LeftMiddle" Value="-5,5"/>
                        <Setter Property="RightTop" Value="5,0"/>
                        <Setter Property="RightBottom" Value="5,10"/>
                     </Trigger>
                     <Trigger Property="Direction" Value="Right">
                        <Setter Property="LeftTop" Value="-5,0"/>
                        <Setter Property="LeftBottom" Value="-5,10"/>
                        <Setter Property="RightMiddle" Value="5,5"/>
                     </Trigger>
                     <Trigger Property="Direction" Value="Out">
                        <Setter Property="LeftMiddle" Value="-5,5"/>
                        <Setter Property="RightMiddle" Value="5,5"/>
                     </Trigger>
                     <Trigger Property="Direction" Value="In">
                        <Setter Property="LeftTop" Value="-5,0"/>
                        <Setter Property="LeftBottom" Value="-5,10"/>
                        <Setter Property="RightTop" Value="5,0"/>
                        <Setter Property="RightBottom" Value="5,10"/>
                     </Trigger>
                  </ControlTemplate.Triggers>
               </ControlTemplate>
            </Setter.Value>
         </Setter>
      </Style>
   </ComboBox.Style>
</ComboBox>
