<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.TextBox.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.ComboBox.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <!--  Style for toolbar buttons  -->
    <Style x:Key="ToolBarButtonBaseStyle" TargetType="{x:Type ButtonBase}">
        <Style.Resources>
            <!--  Disabled all images placed inside a button - most common scenario  -->
            <Style TargetType="Image">
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Opacity" Value="0.5" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Style.Resources>
        <Setter Property="OverridesDefaultStyle" Value="true" />
        <Setter Property="SnapsToDevicePixels" Value="true" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ButtonBase}">
                    <Border x:Name="Border"
                            Background="{DynamicResource TransparentWhiteBrush}"
                            BorderBrush="{DynamicResource TransparentWhiteBrush}"
                            BorderThickness="1">
                        <ContentPresenter Margin="2"
                                          HorizontalAlignment="Center"
                                          VerticalAlignment="Center"
                                          RecognizesAccessKey="True" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsKeyboardFocused" Value="true">
                            <Setter TargetName="Border" Property="Background" Value="{DynamicResource GrayBrush7}" />
                            <Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource GrayBrush7}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter TargetName="Border" Property="Background" Value="{DynamicResource GrayBrush7}" />
                            <Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource GrayBrush7}" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="true">
                            <Setter TargetName="Border" Property="Background" Value="{DynamicResource AccentColorBrush}" />
                            <Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource AccentColorBrush}" />
                        </Trigger>
                        <Trigger Property="CheckBox.IsChecked" Value="true">
                            <Setter TargetName="Border" Property="Background" Value="{DynamicResource AccentColorBrush}" />
                            <Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource AccentColorBrush}" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource GrayBrush3}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--  Style for all types of regular buttons  -->
    <Style x:Key="{x:Static ToolBar.ButtonStyleKey}"
           BasedOn="{StaticResource ToolBarButtonBaseStyle}"
           TargetType="{x:Type Button}" />
    <Style x:Key="{x:Static ToolBar.ToggleButtonStyleKey}"
           BasedOn="{StaticResource ToolBarButtonBaseStyle}"
           TargetType="{x:Type ToggleButton}" />
    <Style x:Key="{x:Static ToolBar.CheckBoxStyleKey}"
           BasedOn="{StaticResource ToolBarButtonBaseStyle}"
           TargetType="{x:Type CheckBox}" />
    <Style x:Key="{x:Static ToolBar.RadioButtonStyleKey}"
           BasedOn="{StaticResource ToolBarButtonBaseStyle}"
           TargetType="{x:Type RadioButton}" />

    <!--  Style for text box inside a toolbar if needed  -->
    <Style x:Key="{x:Static ToolBar.TextBoxStyleKey}"
           BasedOn="{StaticResource MetroTextBox}"
           TargetType="{x:Type TextBox}" />

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

    <!--  Style the toolbar thumb  -->
    <Style x:Key="ToolBarThumbStyle" TargetType="{x:Type Thumb}">
        <Setter Property="Cursor" Value="SizeAll" />
        <Setter Property="OverridesDefaultStyle" Value="true" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Margin="0 3 0 3"
                            Background="Transparent"
                            SnapsToDevicePixels="True">
                        <Rectangle Width="4.9">
                            <Rectangle.Fill>
                                <!--  Brush similar to visual studio, can be improved  -->
                                <DrawingBrush TileMode="Tile"
                                              Viewbox="0,0,5,4"
                                              ViewboxUnits="Absolute"
                                              Viewport="0,0,5,4"
                                              ViewportUnits="Absolute">
                                    <DrawingBrush.Drawing>
                                        <GeometryDrawing Brush="{DynamicResource GrayBrush3}">
                                            <GeometryDrawing.Geometry>
                                                <GeometryGroup>
                                                    <GeometryGroup.Children>
                                                        <RectangleGeometry Rect="0,0,1,1" />
                                                        <RectangleGeometry Rect="4,0,1,1" />
                                                        <RectangleGeometry Rect="2,2,1,1" />
                                                    </GeometryGroup.Children>
                                                </GeometryGroup>
                                            </GeometryDrawing.Geometry>
                                        </GeometryDrawing>
                                    </DrawingBrush.Drawing>
                                </DrawingBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ToolBarOverflowButtonStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="OverridesDefaultStyle" Value="true" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Border Name="Bd"
                            Background="Transparent"
                            CornerRadius="0,3,3,0"
                            SnapsToDevicePixels="true">
                        <Grid>
                            <!--  Overflow button similar to visual studio  -->
                            <Rectangle Name="Rectangle"
                                       Width="6"
                                       Height="1"
                                       Margin="2 8"
                                       VerticalAlignment="Bottom"
                                       Fill="{DynamicResource BlackBrush}" />
                            <Path Name="Arrow"
                                  Margin="2 3"
                                  VerticalAlignment="Bottom"
                                  Data="M 0 0 L 6 0 3 3 Z"
                                  Fill="{DynamicResource BlackBrush}" />
                            <ContentPresenter />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter TargetName="Arrow" Property="Fill" Value="{DynamicResource AccentColorBrush}" />
                            <Setter TargetName="Bd" Property="Background" Value="{DynamicResource GrayBrush7}" />
                            <Setter TargetName="Rectangle" Property="Fill" Value="{DynamicResource AccentColorBrush}" />
                        </Trigger>
                        <Trigger Property="IsKeyboardFocused" Value="true">
                            <Setter TargetName="Arrow" Property="Fill" Value="{DynamicResource AccentColorBrush}" />
                            <Setter TargetName="Bd" Property="Background" Value="{DynamicResource GrayBrush7}" />
                            <Setter TargetName="Rectangle" Property="Fill" Value="{DynamicResource AccentColorBrush}" />
                        </Trigger>
                        <Trigger Property="IsChecked" Value="true">
                            <Setter TargetName="Arrow" Property="Fill" Value="{DynamicResource BlackBrush}" />
                            <Setter TargetName="Bd" Property="Background" Value="{DynamicResource AccentColorBrush}" />
                            <Setter TargetName="Rectangle" Property="Fill" Value="{DynamicResource BlackBrush}" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter TargetName="Arrow" Property="Fill" Value="{DynamicResource TransparentWhiteBrush}" />
                            <Setter TargetName="Rectangle" Property="Fill" Value="{DynamicResource TransparentWhiteBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--  Style the toolbar  -->
    <Style x:Key="{x:Type ToolBar}" TargetType="{x:Type ToolBar}">
        <Setter Property="OverridesDefaultStyle" Value="true" />
        <Setter Property="SnapsToDevicePixels" Value="true" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToolBar}">
                    <Border x:Name="Border"
                            Background="{DynamicResource TransparentWhiteBrush}"
                            BorderBrush="{DynamicResource TransparentWhiteBrush}"
                            BorderThickness="1"
                            CornerRadius="2">
                        <DockPanel>
                            <ToggleButton ClickMode="Press"
                                          DockPanel.Dock="Right"
                                          IsChecked="{Binding Path=IsOverflowOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                          IsEnabled="{TemplateBinding HasOverflowItems}"
                                          Style="{StaticResource ToolBarOverflowButtonStyle}">
                                <Popup x:Name="OverflowPopup"
                                       AllowsTransparency="true"
                                       Focusable="false"
                                       IsOpen="{Binding Path=IsOverflowOpen, RelativeSource={RelativeSource TemplatedParent}}"
                                       Placement="Bottom"
                                       PopupAnimation="Slide"
                                       StaysOpen="false">
                                    <Border x:Name="DropDownBorder"
                                            Background="{DynamicResource ControlBackgroundBrush}"
                                            BorderBrush="{DynamicResource ControlBorderBrush}"
                                            BorderThickness="1">
                                        <ToolBarOverflowPanel x:Name="PART_ToolBarOverflowPanel"
                                                              Margin="2"
                                                              FocusVisualStyle="{x:Null}"
                                                              Focusable="true"
                                                              KeyboardNavigation.DirectionalNavigation="Cycle"
                                                              KeyboardNavigation.TabNavigation="Cycle"
                                                              WrapWidth="200" />
                                    </Border>
                                </Popup>
                            </ToggleButton>

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

                            <ToolBarPanel x:Name="PART_ToolBarPanel"
                                          Margin="0 1 2 2"
                                          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 the toolbar tray  -->
    <Style x:Key="{x:Type ToolBarTray}" TargetType="{x:Type ToolBarTray}">
        <Setter Property="Background" Value="{DynamicResource WindowBackgroundBrush}" />
    </Style>

</ResourceDictionary>