<!--***********************************************************************************

   Extended WPF Toolkit

   Copyright (C) 2007-2013 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license 

   For more features, controls, and fast professional support,
   pick up the Plus Edition at http://xceed.com/wpf_toolkit

   Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids

  **********************************************************************************-->

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Xceed.Wpf.Toolkit"
                    xmlns:conv="clr-namespace:Xceed.Wpf.Toolkit.Core.Converters"
                    xmlns:themes="clr-namespace:Xceed.Wpf.Toolkit.Themes"
                    xmlns:chrome="clr-namespace:Xceed.Wpf.Toolkit.Chromes">

   <conv:InverseBoolConverter x:Key="InverseBoolConverter" />

   <Geometry x:Key="DownArrowGeometry">M 0,1 C0,1 0,0 0,0 0,0 3,0 3,0 3,0 3,1 3,1 3,1 4,1 4,1 4,1 4,0 4,0 4,0 7,0 7,0 7,0 7,1 7,1 7,1 6,1 6,1 6,1 6,2 6,2 6,2 5,2 5,2 5,2 5,3 5,3 5,3 4,3 4,3 4,3 4,4 4,4 4,4 3,4 3,4 3,4 3,3 3,3 3,3 2,3 2,3 2,3 2,2 2,2 2,2 1,2 1,2 1,2 1,1 1,1 1,1 0,1 0,1 z</Geometry>

   <Style x:Key="ComboBoxToggleButton"
          TargetType="{x:Type ToggleButton}">
      <Setter Property="OverridesDefaultStyle"
              Value="true" />
      <Setter Property="IsTabStop"
              Value="false" />
      <Setter Property="Focusable"
              Value="false" />
      <Setter Property="Padding"
              Value="2" />
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type ToggleButton}">
               <chrome:ButtonChrome x:Name="Chrome"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    Background="{TemplateBinding Background}"
                                    CornerRadius="0"
                                    RenderEnabled="{TemplateBinding IsEnabled}"
                                    RenderMouseOver="{Binding IsMouseOver, ElementName=PART_DropDownButton}"
                                    RenderNormal="False"
                                    RenderPressed="{Binding IsPressed, ElementName=PART_DropDownButton}"
                                    SnapsToDevicePixels="true">
                  <Grid>
                     <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"
                                          Width="0" />
                     </Grid.ColumnDefinitions>

                     <TextBox x:Name="TextBox"
                              Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
                              Foreground="{TemplateBinding Foreground}"
                              BorderThickness="0"
                              Background="Transparent"
                              IsReadOnly="True"
                              Focusable="False"
                              Cursor="Arrow"
                              Margin="{TemplateBinding Padding}"
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                              HorizontalScrollBarVisibility="Hidden"
                              VerticalScrollBarVisibility="Hidden" />
                     <Grid Grid.Column="1"
                           HorizontalAlignment="Right"
                           Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
                        <Path x:Name="Arrow"
                              Data="{StaticResource DownArrowGeometry}"
                              Fill="Black"
                              HorizontalAlignment="Center"
                              Margin="3,0,3,0"
                              VerticalAlignment="Center" />
                     </Grid>
                  </Grid>
               </chrome:ButtonChrome>
               <ControlTemplate.Triggers>
                  <Trigger Property="IsChecked"
                           Value="true">
                     <Setter Property="RenderPressed"
                             TargetName="Chrome"
                             Value="true" />
                  </Trigger>
                  <Trigger Property="IsEnabled"
                           Value="false">
                     <Setter Property="Fill"
                             TargetName="Arrow"
                             Value="#AFAFAF" />
                  </Trigger>
                  <DataTrigger Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type local:CheckComboBox}}}"
                               Value="True">
                     <Setter Property="IsReadOnly"
                             Value="False"
                             TargetName="TextBox" />
                     <Setter Property="Focusable"
                             Value="True"
                             TargetName="TextBox" />
                     <Setter Property="Cursor"
                             Value="{x:Null}"
                             TargetName="TextBox" />
                  </DataTrigger>
               </ControlTemplate.Triggers>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

   <Style TargetType="{x:Type local:CheckComboBox}">
      <Setter Property="Foreground"
              Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
      <Setter Property="Background"
              Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
      <Setter Property="BorderBrush"
              Value="{DynamicResource {x:Static themes:ResourceKeys.ControlNormalBorderKey}}" />
      <Setter Property="BorderThickness"
              Value="1" />
      <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
              Value="Auto" />
      <Setter Property="ScrollViewer.VerticalScrollBarVisibility"
              Value="Auto" />
      <Setter Property="Padding"
              Value="2" />
      <Setter Property="ScrollViewer.CanContentScroll"
              Value="true" />
      <Setter Property="ScrollViewer.PanningMode"
              Value="Both" />
      <Setter Property="Stylus.IsFlicksEnabled"
              Value="False" />
      <Setter Property="VerticalContentAlignment"
              Value="Center" />
      <Setter Property="HorizontalContentAlignment"
              Value="Stretch" />
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:CheckComboBox}">
               <Grid x:Name="MainGrid"
                     SnapsToDevicePixels="true">
                  <Popup x:Name="PART_Popup"
                         AllowsTransparency="true"
                         IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                         StaysOpen="False"
                         Margin="1"
                         PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}"
                         Placement="Bottom">
                     <Grid MinWidth="{Binding ActualWidth, ElementName=MainGrid}">
                        <Border x:Name="DropDownBorder"
                                MaxHeight="{Binding MaxDropDownHeight,  RelativeSource={RelativeSource TemplatedParent}}"
                                BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"
                                BorderThickness="1"
                                Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
                           <ScrollViewer x:Name="DropDownScrollViewer">
                              <Grid RenderOptions.ClearTypeHint="Enabled">
                                 <Canvas HorizontalAlignment="Left"
                                         Height="0"
                                         VerticalAlignment="Top"
                                         Width="0">
                                    <Rectangle x:Name="OpaqueRect"
                                               Fill="{Binding Background, ElementName=DropDownBorder}"
                                               Height="{Binding ActualHeight, ElementName=DropDownBorder}"
                                               Width="{Binding ActualWidth, ElementName=DropDownBorder}" />
                                 </Canvas>
                                 <ItemsPresenter x:Name="PART_ItemsPresenter"
                                                 KeyboardNavigation.DirectionalNavigation="Contained"
                                                 SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                              </Grid>
                           </ScrollViewer>
                        </Border>
                     </Grid>
                  </Popup>

                  <Border  Background="{TemplateBinding Background}"
                           BorderBrush="{TemplateBinding BorderBrush}"
                           BorderThickness="{TemplateBinding BorderThickness}" />
                  <ToggleButton x:Name="PART_DropDownButton"
                                Content="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                Background="{TemplateBinding Background}"
                                Focusable="False"
                                IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                Style="{StaticResource ComboBoxToggleButton}"
                                Padding="{TemplateBinding Padding}"
                                VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                IsHitTestVisible="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource InverseBoolConverter}}" />
               </Grid>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
      <Style.Triggers>
         <Trigger Property="IsMouseOver"
                  Value="True">
            <Setter Property="BorderBrush"
                    Value="{DynamicResource {x:Static themes:ResourceKeys.ControlMouseOverBorderKey}}" />
         </Trigger>
         <Trigger Property="IsKeyboardFocusWithin"
                  Value="True">
            <Setter Property="BorderBrush"
                    Value="{DynamicResource {x:Static themes:ResourceKeys.ControlSelectedBorderKey}}" />
         </Trigger>
      </Style.Triggers>
   </Style>

</ResourceDictionary>
