<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:bpa="clr-namespace:BPA.UIControl">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/BPA.UIControl;component/Themes/ToggleButton.xaml" />
        <ResourceDictionary Source="pack://application:,,,/BPA.UIControl;component/Themes/ComboBox.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="{x:Static ToolBar.SeparatorStyleKey}" TargetType="{x:Type Separator}">
        <Setter Property="Margin" Value="5" />
        <Setter Property="BorderBrush" Value="{DynamicResource Border}" />
        <Setter Property="BorderThickness" Value="1 1 0 0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Separator}">
                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ToolBarButtonBaseStyle"
           BasedOn="{StaticResource TextButton}"
           TargetType="{x:Type Button}">
        <Setter Property="Margin" Value="0 0 2 0" />
        <Setter Property="Foreground" Value="{DynamicResource DefaultForeground}" />
    </Style>

    <Style x:Key="ToolBarToggleButtonStyle"
           BasedOn="{StaticResource RubyerToggleButton}"
           TargetType="{x:Type ToggleButton}">
        <Setter Property="Margin" Value="0 0 2 0" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Foreground" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="bpa:ControlHelper.FocusedBrush" Value="{DynamicResource Mask}" />
        <Setter Property="bpa:ControlHelper.FocusedForegroundBrush" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="bpa:ControlHelper.MaskOpacity" Value="0.6" />
    </Style>

    <Style x:Key="{x:Static ToolBar.ButtonStyleKey}"
           BasedOn="{StaticResource ToolBarButtonBaseStyle}"
           TargetType="{x:Type Button}" />

    <Style x:Key="{x:Static ToolBar.ToggleButtonStyleKey}"
           BasedOn="{StaticResource ToolBarToggleButtonStyle}"
           TargetType="{x:Type ToggleButton}" />

    <Style x:Key="{x:Static ToolBar.ComboBoxStyleKey}"
           BasedOn="{StaticResource RubyerComboBox}"
           TargetType="{x:Type ComboBox}" />

    <Style x:Key="{x:Static ToolBar.CheckBoxStyleKey}"
           BasedOn="{StaticResource ToolBarToggleButtonStyle}"
           TargetType="{x:Type CheckBox}" />

    <Style x:Key="{x:Static ToolBar.RadioButtonStyleKey}"
           BasedOn="{StaticResource ToolBarToggleButtonStyle}"
           TargetType="{x:Type RadioButton}" />

    <Style x:Key="{x:Static ToolBar.TextBoxStyleKey}"
           BasedOn="{StaticResource RubyerTextBox}"
           TargetType="{x:Type TextBox}">
        <Setter Property="AllowDrop" Value="True" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
    </Style>

    <Style x:Key="ToolBarThumbStyle" TargetType="{x:Type Thumb}">
        <Setter Property="Cursor" Value="SizeAll" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Margin" Value="2 2" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Background="{TemplateBinding Background}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Rectangle>
                            <Rectangle.Fill>
                                <DrawingBrush TileMode="Tile"
                                              Viewbox="0 0 8 8"
                                              ViewboxUnits="Absolute"
                                              Viewport="0 0 4 4"
                                              ViewportUnits="Absolute">
                                    <DrawingBrush.Drawing>
                                        <DrawingGroup>
                                            <GeometryDrawing Brush="{DynamicResource Mask}" Geometry="M 4 4 L 4 8 L 8 8 L 8 4 z" />
                                        </DrawingGroup>
                                    </DrawingBrush.Drawing>
                                </DrawingBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ToolBarOverflowButtonStyle"
           BasedOn="{StaticResource RubyerToggleButton}"
           TargetType="{x:Type ToggleButton}">
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="bpa:ControlHelper.FocusedBrush" Value="{DynamicResource Mask}" />
        <Setter Property="bpa:ControlHelper.FocusedForegroundBrush" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Border x:Name="border"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Grid>
                            <bpa:ControlMask x:Name="mask"
                                             Background="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                             CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                             IsActive="{TemplateBinding IsChecked}"
                                             MaskOpacity="{Binding Path=(bpa:ControlHelper.MaskOpacity), RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                            <bpa:Icon Height="Auto"
                                      VerticalAlignment="Bottom"
                                      Type="ArrowDownSFill" />
                            <ContentPresenter />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="RubyerToolBar" TargetType="{x:Type ToolBar}">
        <Setter Property="BorderBrush" Value="{DynamicResource Border}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Margin" Value="0 2" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="VerticalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalAlignment" Value="Stretch" />
        <Setter Property="bpa:ControlHelper.CornerRadius" Value="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource AncestorType=ToolBarTray}}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToolBar}">
                    <Border x:Name="Border"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}">
                        <DockPanel>
                            <ToggleButton Style="{StaticResource ToolBarOverflowButtonStyle}"
                                          ClickMode="Press"
                                          DockPanel.Dock="Right"
                                          IsChecked="{Binding IsOverflowOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                          IsEnabled="{TemplateBinding HasOverflowItems}">
                                <Popup x:Name="OverflowPopup"
                                       AllowsTransparency="True"
                                       Focusable="False"
                                       IsOpen="{Binding IsOverflowOpen, RelativeSource={RelativeSource TemplatedParent}}"
                                       Placement="Bottom"
                                       PopupAnimation="Fade"
                                       StaysOpen="False">
                                    <Grid Margin="5">
                                        <Border Background="{DynamicResource FloatBackground}"
                                                CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                                Effect="{DynamicResource AllDirectionEffect}" />

                                        <Border x:Name="DropDownBorder"
                                                Background="{DynamicResource FloatBackground}"
                                                CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}">
                                            <ToolBarOverflowPanel x:Name="PART_ToolBarOverflowPanel"
                                                                  Margin="5"
                                                                  FocusVisualStyle="{x:Null}"
                                                                  Focusable="True"
                                                                  KeyboardNavigation.DirectionalNavigation="Cycle"
                                                                  KeyboardNavigation.TabNavigation="Cycle"
                                                                  WrapWidth="200" />
                                        </Border>
                                    </Grid>
                                </Popup>
                            </ToggleButton>

                            <Thumb x:Name="ToolBarThumb"
                                   Style="{StaticResource ToolBarThumbStyle}"
                                   Width="10" />

                            <ToolBarPanel x:Name="PART_ToolBarPanel" IsItemsHost="True" />
                        </DockPanel>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsOverflowOpen" Value="True">
                            <Setter TargetName="ToolBarThumb" Property="IsEnabled" Value="False" />
                        </Trigger>
                        <Trigger Property="ToolBarTray.IsLocked" Value="True">
                            <Setter TargetName="ToolBarThumb" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="RubyerToolBarTray" TargetType="{x:Type ToolBarTray}">
        <Setter Property="Background" Value="{DynamicResource HeaderBackground}" />
        <Setter Property="bpa:ControlHelper.CornerRadius" Value="{DynamicResource AllControlCornerRadius}" />
    </Style>
</ResourceDictionary>