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

  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="../Themes/MetroDark/MetroDark.MSControls.Core.Implicit.xaml"/>
  </ResourceDictionary.MergedDictionaries>

  <Style BasedOn="{StaticResource ToggleButtonStyle}" TargetType="{x:Type local:DropDownMenuButton}">
    <Setter Property="FontFamily" Value="Meiryo"/>
    <Setter Property="FontSize" Value="12"/>
    <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
    <Setter Property="Padding" Value="10,0"/>
    <Setter Property="MinHeight" Value="30"/>
    <Setter Property="MinWidth" Value="30"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ToggleButton}">
          <Grid>
            <VisualStateManager.VisualStateGroups>
              <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal"/>
                <VisualState x:Name="MouseOver">
                  <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Bd" Storyboard.TargetProperty="Fill">
                      <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonHoverBackgroundBrush}"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Bd" Storyboard.TargetProperty="Stroke">
                      <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonHoverBorderBrush}"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Foreground" Storyboard.TargetName="contentControl">
                      <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource LightForegroundBrush}"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Fill" Storyboard.TargetName="Arrow">
                      <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource LightForegroundBrush}"/>
                    </ObjectAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="Pressed">
                  <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Bd" Storyboard.TargetProperty="Fill">
                      <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonPressedBackgroundBrush}"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Bd" Storyboard.TargetProperty="Stroke">
                      <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ButtonPressedBorderBrush}"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Foreground" Storyboard.TargetName="contentControl">
                      <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource LightForegroundBrush}"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Fill" Storyboard.TargetName="Arrow">
                      <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource LightForegroundBrush}"/>
                    </ObjectAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="Disabled">
                  <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="DisabledVisualElement">
                      <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                          <Visibility>Visible</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                      </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
              </VisualStateGroup>
              <VisualStateGroup x:Name="CheckStates">
                <VisualState x:Name="Checked">
                  <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="checked">
                      <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                          <Visibility>Visible</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                      </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="contentControl">
                      <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                          <Visibility>Collapsed</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                      </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="contentControl1">
                      <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                          <Visibility>Visible</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                      </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Foreground" Storyboard.TargetName="contentControl1">
                      <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource LightForegroundBrush}"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="Arrow">
                      <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                          <Visibility>Collapsed</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                      </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="Arrow1">
                      <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                          <Visibility>Visible</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                      </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Fill" Storyboard.TargetName="Arrow1">
                      <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource LightForegroundBrush}"/>
                    </ObjectAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="Unchecked"/>
                <VisualState x:Name="Indeterminate"/>
              </VisualStateGroup>
              <VisualStateGroup x:Name="FocusStates">
                <VisualState x:Name="Focused">
                  <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="FocusedVisualElement">
                      <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                          <Visibility>Visible</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                      </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="Unfocused"/>
              </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Rectangle x:Name="Bd" Fill="{StaticResource ButtonBackgroundBrush}" Stroke="{StaticResource ButtonBorderBrush}" StrokeThickness="1"/>
            <Rectangle x:Name="checked" Fill="{StaticResource ButtonPressedBackgroundBrush}" Stroke="{StaticResource ButtonPressedBorderBrush}" StrokeThickness="1" Visibility="Collapsed"/>
            <ContentControl x:Name="contentControl" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}" Foreground="{TemplateBinding Foreground}">
              <ContentPresenter x:Name="contentPresenter" Margin="0,0,20,0"/>
            </ContentControl>
            <Path x:Name="Arrow" Width="8" Height="6" Margin="8,0,8,0" Stretch="Fill" Fill="{TemplateBinding Foreground}" Data="F1 M 57.5692,88L 99.1384,16L 16,16L 57.5692,88 Z " VerticalAlignment="Center" HorizontalAlignment="Right"/>
            <ContentControl x:Name="contentControl1" Visibility="Collapsed" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}" Foreground="{StaticResource ForegroundBrush}">
              <ContentPresenter x:Name="contentPresenter1" Margin="0,0,20,0"/>
            </ContentControl>
            <Path x:Name="Arrow1" Visibility="Collapsed" Width="8" Height="6" Margin="8,0,8,0" Stretch="Fill" Fill="{StaticResource ForegroundBrush}" Data="F1 M 57.5692,88L 99.1384,16L 16,16L 57.5692,88 Z " VerticalAlignment="Center" HorizontalAlignment="Right"/>
            <Rectangle x:Name="FocusedVisualElement" Stroke="{StaticResource ButtonPressedBorderBrush}" Visibility="Collapsed" StrokeThickness="2"/>
            <Rectangle x:Name="DisabledVisualElement" Fill="{StaticResource DisabledVisualElement}" Visibility="Collapsed"/>
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  
  <!-- Used for Checkmark, Radio button, TreeViewItem, Expander ToggleButton glyphs -->
  <SolidColorBrush x:Key="GlyphBrush" Color="#444"/>

  <!-- SelectedBackgroundBrush is used for the Selected item in ListBoxItem, ComboBoxItem-->
  <SolidColorBrush x:Key="SelectedBackgroundBrush" Color="#DDD"/>

  <!-- Disabled Brushes are used for the Disabled look of each control -->
  <SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888"/>

  <!-- NormalBrush is used as the Background for SimpleButton, SimpleRepeatButton -->
  <LinearGradientBrush x:Key="NormalBrush" EndPoint="0,1" StartPoint="0,0">
    <GradientStop Color="#EEE" Offset="0.0"/>
    <GradientStop Color="#CCC" Offset="1.0"/>
  </LinearGradientBrush>
  <LinearGradientBrush x:Key="NormalBorderBrush" EndPoint="0,1" StartPoint="0,0">
    <GradientStop Color="#CCC" Offset="0.0"/>
    <GradientStop Color="#444" Offset="1.0"/>
  </LinearGradientBrush>

  <Style x:Key="ButtonFocusVisual">
    <Setter Property="Control.Template">
      <Setter.Value>
        <ControlTemplate>
          <Rectangle SnapsToDevicePixels="true" Margin="3" Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1"/>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <LinearGradientBrush x:Key="ButtonNormalBackgroundFill" EndPoint="0.5,1" StartPoint="0.5,0">
    <GradientStop Color="#FFFFFFFF" Offset="0"/>
    <GradientStop Color="#FFF0F0EA" Offset="0.9"/>
  </LinearGradientBrush>

  <SolidColorBrush x:Key="ButtonBorder" Color="#FF003C74"/>

  <Style x:Key="MainButtonStyle" TargetType="{x:Type Button}" BasedOn="{x:Null}">
    <Setter Property="Margin" Value="-1,-1,0,-1"/>
    <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Button}">
          <Grid>
            <Rectangle x:Name="rect" Fill="Transparent" Stroke="#00000000"/>
            <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True" Margin="0,0,0,2"/>
            <Rectangle x:Name="FocusedVisualElement" Stroke="{StaticResource ButtonPressedBorderBrush}" Visibility="Collapsed" StrokeThickness="2"/>
            <Rectangle x:Name="DisabledVisualElement" Fill="{StaticResource DisabledVisualElement}" Visibility="Collapsed"/>
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="IsFocused" Value="True">
              <Setter TargetName="FocusedVisualElement" Property="Visibility" Value="Visible"/>
            </Trigger>
            <Trigger Property="IsDefaulted" Value="True"/>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter TargetName="rect" Property="Fill" Value="{StaticResource ButtonHoverBackgroundBrush}"/>
              <Setter TargetName="rect" Property="StrokeThickness" Value="1"/>
              <Setter TargetName="rect" Property="Stroke" Value="{StaticResource ButtonHoverBorderBrush}"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
              <Setter TargetName="rect" Property="Fill" Value="{StaticResource ButtonPressedBackgroundBrush}"/>
              <Setter Property="Foreground" Value="{StaticResource LightForegroundBrush}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter TargetName="DisabledVisualElement" Property="Visibility" Value="Visible"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type local:SplitButton}">
    <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
    <Setter Property="Background" Value="{StaticResource ButtonBackgroundBrush}"/>
    <Setter Property="BorderBrush" Value="{StaticResource ButtonBorderBrush}"/>
    <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
    <Setter Property="HorizontalAlignment" Value="Center"/>
    <Setter Property="VerticalAlignment" Value="Center"/>
    <Setter Property="MinHeight" Value="30"/>
    <Setter Property="MinWidth" Value="30"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type local:SplitButton}">
          <Border SnapsToDevicePixels="True" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" BorderThickness="1">
            <Grid>
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
              </Grid.ColumnDefinitions>
              <Button x:Name="PART_Button" Grid.Column="0" Style="{DynamicResource MainButtonStyle}"/>
              <Border x:Name="line" Grid.Column="1" Visibility="Visible" BorderThickness="1,0,0,0" BorderBrush="#FF111111"/>
              <Border x:Name="lineGrey" Grid.Column="2" Visibility="Visible" BorderThickness="1,0,0,0" BorderBrush="#FF666666"/>
              <Rectangle x:Name="CheckedVisualElement" Grid.Column="3" Fill="{StaticResource ButtonPressedBackgroundBrush}" Visibility="Collapsed" StrokeThickness="2"/>
              <Path x:Name="Arrow" Grid.Column="3" Width="8" Height="6" Margin="6,0,6,0" Stretch="Fill" Fill="{TemplateBinding Foreground}" Data="F1 M 57.5692,88L 99.1384,16L 16,16L 57.5692,88 Z "/>
              <Rectangle x:Name="FocusedVisualElement" Grid.Column="3" Stroke="{StaticResource ButtonPressedBorderBrush}" Visibility="Collapsed" StrokeThickness="2"/>
              <Rectangle x:Name="DisabledVisualElement" Grid.ColumnSpan="4" Fill="{StaticResource DisabledVisualElement}" Visibility="Collapsed"/>
            </Grid>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsKeyboardFocused" Value="True">
              <Setter TargetName="FocusedVisualElement" Property="Visibility" Value="Visible"/>
            </Trigger>
            <Trigger Property="ToggleButton.IsPressed" Value="True">
              <Setter TargetName="CheckedVisualElement" Property="Visibility" Value="Visible"/>
              <Setter TargetName="Arrow" Property="Fill" Value="{StaticResource LightForegroundBrush}"/>
            </Trigger>
            <Trigger Property="ToggleButton.IsChecked" Value="True">
              <Setter TargetName="CheckedVisualElement" Property="Visibility" Value="Visible"/>
              <Setter TargetName="Arrow" Property="Fill" Value="{StaticResource LightForegroundBrush}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter TargetName="DisabledVisualElement" Property="Visibility" Value="Visible"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!--
  <Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    <Setter Property="Background" Value="#00FFFFFF"/>
    <Setter Property="HorizontalAlignment" Value="Stretch"/>
    <Setter Property="VerticalAlignment" Value="Stretch"/>
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    <Setter Property="VerticalContentAlignment" Value="Stretch"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Button}">
          <Border x:Name="Bd" SnapsToDevicePixels="True" Background="{TemplateBinding Background}">
            <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsPressed" Value="True">
              <Setter Property="Background" TargetName="Bd" Value="#FF98B5E2"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
  -->

  <DataTemplate x:Key="SplitMenuIconStyle">
    <Image Source="{Binding XPath=.}"></Image>
  </DataTemplate>

  <ControlTemplate x:Key="SplitMenuItemTemplate" TargetType="MenuItem">
    <Border Name="Border">
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto" SharedSizeGroup="Icon"/>
          <ColumnDefinition Width="*"/>
          <ColumnDefinition Width="Auto" SharedSizeGroup="Shortcut"/>
          <ColumnDefinition Width="13"/>
        </Grid.ColumnDefinitions>
        <ContentPresenter x:Name="Icon"
          ContentTemplate="{StaticResource SplitMenuIconStyle}"
          Margin="6,0,6,0"
          VerticalAlignment="Center"
          ContentSource="Icon"
          Height="16" Width="16"
          Visibility="Hidden"/>
        <Border x:Name="Check"
          Width="13" Height="13"
          Visibility="Collapsed"
          Margin="6,0,6,0"
          Background="{StaticResource NormalBrush}"
          BorderThickness="1"
          BorderBrush="{StaticResource NormalBorderBrush}">
          <Path x:Name="CheckMark"
            Width="7" Height="7"
            Visibility="Hidden"
            SnapsToDevicePixels="False"
            Stroke="{StaticResource GlyphBrush}"
            StrokeThickness="2"
            Data="M 0 0 L 7 7 M 0 7 L 7 0"/>
        </Border>
        <ContentPresenter x:Name="HeaderHost"
          Grid.Column="1"
          ContentSource="Header"
          RecognizesAccessKey="True"
          Margin="5,2,0,2"
          VerticalAlignment="Center"/>
        <TextBlock x:Name="InputGestureText"
          Grid.Column="2"
          Text="{TemplateBinding InputGestureText}"
          Margin="5,2,0,2"
          DockPanel.Dock="Right"/>
      </Grid>
    </Border>
    <ControlTemplate.Triggers>
      <Trigger Property="Icon" Value="{x:Null}">
        <Setter TargetName="Icon" Property="Visibility" Value="Hidden"/>
      </Trigger>
      <Trigger Property="IsChecked" Value="true">
        <Setter TargetName="CheckMark" Property="Visibility" Value="Visible"/>
      </Trigger>
      <Trigger Property="IsCheckable" Value="true">
        <Setter TargetName="Check" Property="Visibility" Value="Visible"/>
        <Setter TargetName="Icon" Property="Visibility" Value="Hidden"/>
      </Trigger>
      <Trigger Property="IsHighlighted" Value="true">
        <Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}"/>
      </Trigger>
      <Trigger Property="IsEnabled" Value="false">
        <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
      </Trigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>


  <Style TargetType="{x:Type local:PathTrimTextBlock}">
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="FontFamily" Value="Meiryo"/>
    <Setter Property="FontSize" Value="12"/>
    <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
    <Setter Property="TextTrimming" Value="CharacterEllipsis"/>
    <Style.Triggers>
      <Trigger Property="IsEnabled" Value="false">
        <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
      </Trigger>
    </Style.Triggers>
  </Style>

</ResourceDictionary>
