<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:Fluent="clr-namespace:Fluent"
                    xmlns:FluentHelpers="clr-namespace:Fluent.Helpers"
                    xmlns:converters="clr-namespace:Fluent.Converters"
                    xmlns:styleSelectors="clr-namespace:Fluent.StyleSelectors"
                    mc:Ignorable="d">
    <converters:ApplicationMenuRightScrollViewerExtractorConverter x:Key="ApplicationMenuRightScrollViewerExtractorConverter" />

    <!-- Second level-->

    <!--Menu Item Template-->
    <ControlTemplate x:Key="ApplicationMenuSecondLevelItemTemplate"
                     TargetType="{x:Type Fluent:MenuItem}">
        <ControlTemplate.Resources>
            <ResourceDictionary>
                <Style x:Key="{x:Type ScrollViewer}"
                       TargetType="{x:Type ScrollViewer}"
                       BasedOn="{StaticResource MenuScrollViewer}" />
            </ResourceDictionary>
        </ControlTemplate.Resources>
        <Grid Width="Auto"
              MinHeight="53"
              Height="Auto"
              Background="Transparent">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="44" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Border x:Name="border"
                    HorizontalAlignment="Stretch"
                    Margin="0"
                    Width="Auto"
                    Visibility="Collapsed"
                    Background="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.Background}"
                    BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.BorderBrush}"
                    BorderThickness="1"
                    CornerRadius="2"
                    Grid.Column="0"
                    Grid.ColumnSpan="3" />
            <TextBlock x:Name="textBlock"
                       FontWeight="Bold"
                       Text="{TemplateBinding Header}"
                       Width="Auto"
                       Height="Auto"
                       Margin="9,5,3,3"
                       VerticalAlignment="Top"
                       Grid.Column="1"
                       d:LayoutOverrides="Width"
                       TextTrimming="CharacterEllipsis" />
            <TextBlock x:Name="textBlockDesc"
                       Text="{TemplateBinding Description}"
                       Width="Auto"
                       HorizontalAlignment="Stretch"
                       Height="Auto"
                       Margin="9,22,3,3"
                       VerticalAlignment="Top"
                       Grid.Column="1"
                       d:LayoutOverrides="Width"
                       TextWrapping="Wrap" />
            <Rectangle x:Name="rectangle"
                       Fill="{DynamicResource Fluent.Ribbon.Brushes.ApplicationMenuItem.CheckBox.Background}"
                       Stroke="{DynamicResource Fluent.Ribbon.Brushes.ApplicationMenuItem.CheckBox.BorderBrush}"
                       Grid.ColumnSpan="1"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center"
                       Width="40"
                       Height="40"
                       RadiusX="1"
                       RadiusY="1"
                       Visibility="Collapsed" />
            <Image x:Name="image"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Top"
                   Margin="0,4,0,0"
                   Width="32"
                   Height="32"
                   Stretch="Uniform"
                   Source="{DynamicResource Fluent.Ribbon.Images.Checked}"
                   Visibility="Collapsed"
                   SnapsToDevicePixels="True" />
            <ContentPresenter x:Name="iconImage"
                              HorizontalAlignment="Center"
                              Height="32"
                              VerticalAlignment="Top"
                              Margin="3,4,2,2"
                              Content="{converters:ObjectToImageConverter {Binding Icon, RelativeSource={RelativeSource TemplatedParent}}, '32,32', {Binding RelativeSource={RelativeSource TemplatedParent}}}"
                              Width="32"
                              SnapsToDevicePixels="True" />
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked"
                     Value="True">
                <Setter Property="Visibility"
                        TargetName="rectangle"
                        Value="Visible" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Icon"
                               Value="{x:Null}" />
                    <Condition Property="IsChecked"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="image"
                        Value="Visible" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsHighlighted"
                               Value="True" />
                    <Condition Property="IsEnabled"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="border"
                        Value="Visible" />
            </MultiTrigger>
            <Trigger Property="IsEnabled"
                     Value="False">
                <Setter Property="Opacity"
                        TargetName="iconImage"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="image"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="textBlock"
                        Value="0.5" />
                <Setter Property="Effect"
                        TargetName="iconImage">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
                <Setter Property="Effect"
                        TargetName="image">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!--Header Menu Item Template-->
    <ControlTemplate x:Key="HeaderApplicationMenuSecondLevelItemTemplate"
                     TargetType="{x:Type Fluent:MenuItem}">
        <ControlTemplate.Resources>
            <ResourceDictionary>
                <Style x:Key="{x:Type ScrollViewer}"
                       TargetType="{x:Type ScrollViewer}"
                       BasedOn="{StaticResource MenuScrollViewer}" />
            </ResourceDictionary>
        </ControlTemplate.Resources>
        <Grid Width="Auto"
              MinHeight="53"
              Height="Auto"
              Background="Transparent">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="44" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Border x:Name="border"
                    HorizontalAlignment="Stretch"
                    Margin="0"
                    Width="Auto"
                    Visibility="Collapsed"
                    Background="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.Background}"
                    BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.BorderBrush}"
                    BorderThickness="1"
                    CornerRadius="2"
                    Grid.Column="0"
                    Grid.ColumnSpan="3" />
            <TextBlock x:Name="textBlock"
                       FontWeight="Bold"
                       Text="{TemplateBinding Header}"
                       Width="Auto"
                       Height="Auto"
                       Margin="9,5,3,3"
                       VerticalAlignment="Top"
                       Grid.Column="1"
                       d:LayoutOverrides="Width"
                       TextTrimming="CharacterEllipsis" />
            <TextBlock x:Name="textBlockDesc"
                       Text="{TemplateBinding Description}"
                       Width="Auto"
                       HorizontalAlignment="Stretch"
                       Height="Auto"
                       Margin="9,22,3,3"
                       VerticalAlignment="Top"
                       Grid.Column="1"
                       d:LayoutOverrides="Width"
                       TextWrapping="Wrap" />
            <Rectangle x:Name="rectangle"
                       Fill="{DynamicResource Fluent.Ribbon.Brushes.ApplicationMenuItem.CheckBox.Background}"
                       Stroke="{DynamicResource Fluent.Ribbon.Brushes.ApplicationMenuItem.CheckBox.BorderBrush}"
                       Grid.ColumnSpan="1"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center"
                       Width="40"
                       Height="40"
                       RadiusX="1"
                       RadiusY="1"
                       Visibility="Collapsed" />
            <Image x:Name="image"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Top"
                   Margin="0,4,0,0"
                   Width="32"
                   Height="32"
                   Stretch="Uniform"
                   Source="{DynamicResource Fluent.Ribbon.Images.Checked}"
                   Visibility="Collapsed"
                   SnapsToDevicePixels="True" />
            <ContentPresenter x:Name="iconImage"
                              HorizontalAlignment="Center"
                              Height="32"
                              VerticalAlignment="Top"
                              Margin="3,4,2,2"
                              Content="{converters:ObjectToImageConverter {Binding Icon, RelativeSource={RelativeSource TemplatedParent}}, '32,32', {Binding RelativeSource={RelativeSource TemplatedParent}}}"
                              Width="32"
                              SnapsToDevicePixels="True" />
            <Path x:Name="path"
                  Stretch="Fill"
                  Stroke="{x:Null}"
                  HorizontalAlignment="Right"
                  Margin="1,0,9,0"
                  Width="4"
                  Data="M0,0L1,1 0,2z"
                  Height="7"
                  Grid.Column="3"
                  Fill="{DynamicResource Fluent.Ribbon.MenuItem.SubMenu.Arrow.Fill}" />
            <Popup x:Name="PART_Popup"
                   Placement="Right"
                   IsOpen="{TemplateBinding IsSubmenuOpen}"
                   AllowsTransparency="True"
                   Focusable="False"
                   PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
                   Margin="0,0,0,0"
                   VerticalAlignment="Top"
                   Grid.ColumnSpan="2">
                <Grid Name="DropDown"
                      SnapsToDevicePixels="True"
                      Margin="0"
                      VerticalAlignment="Stretch">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="4" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="4" />
                    </Grid.ColumnDefinitions>
                    <Rectangle HorizontalAlignment="Left"
                               VerticalAlignment="Top"
                               Width="4"
                               Height="4"
                               Grid.Row="1"
                               Grid.Column="1"
                               StrokeThickness="0"
                               Margin="-1,-1,0,0">
                        <Rectangle.Fill>
                            <RadialGradientBrush RadiusX="0.984"
                                                 Center="0.017,0.002"
                                                 GradientOrigin="0.017,0.002"
                                                 RadiusY="1">
                                <GradientStop Color="#3F000000"
                                              Offset="0" />
                                <GradientStop Color="Transparent"
                                              Offset="1" />
                            </RadialGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle StrokeThickness="0"
                               HorizontalAlignment="Left"
                               Margin="-1,3,0,0"
                               VerticalAlignment="Top"
                               Width="4"
                               Height="4"
                               Grid.Column="1"
                               Grid.Row="0">
                        <Rectangle.Fill>
                            <RadialGradientBrush Center="0.032,1.01"
                                                 GradientOrigin="0.032,1.01"
                                                 RadiusX="0.984"
                                                 RadiusY="1">
                                <GradientStop Color="#3F000000"
                                              Offset="0" />
                                <GradientStop Color="Transparent"
                                              Offset="1" />
                            </RadialGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle StrokeThickness="0"
                               HorizontalAlignment="Left"
                               Margin="3,-1,0,0"
                               VerticalAlignment="Top"
                               Width="4"
                               Height="4"
                               Grid.Column="0"
                               Grid.Row="1">
                        <Rectangle.Fill>
                            <RadialGradientBrush Center="0.996,0.027"
                                                 GradientOrigin="0.996,0.027"
                                                 RadiusX="0.984"
                                                 RadiusY="1">
                                <GradientStop Color="#3F000000"
                                              Offset="0" />
                                <GradientStop Color="Transparent"
                                              Offset="1" />
                            </RadialGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle StrokeThickness="0"
                               HorizontalAlignment="Stretch"
                               Margin="7,-1,1,0"
                               VerticalAlignment="Top"
                               Width="Auto"
                               Height="4"
                               Grid.Column="0"
                               Grid.Row="1">
                        <Rectangle.Fill>
                            <LinearGradientBrush EndPoint="0.5,1"
                                                 StartPoint="0.5,0"
                                                 MappingMode="RelativeToBoundingBox">
                                <GradientStop Color="#3F000000"
                                              Offset="0" />
                                <GradientStop Color="Transparent"
                                              Offset="1" />
                            </LinearGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle StrokeThickness="0"
                               HorizontalAlignment="Left"
                               Margin="-1,7,0,1"
                               VerticalAlignment="Stretch"
                               Width="4"
                               Height="Auto"
                               Grid.Column="1"
                               Grid.Row="0">
                        <Rectangle.Fill>
                            <LinearGradientBrush EndPoint="1,0.5"
                                                 StartPoint="0,0.5"
                                                 MappingMode="RelativeToBoundingBox">
                                <GradientStop Color="#3F000000"
                                              Offset="0" />
                                <GradientStop Color="Transparent"
                                              Offset="1" />
                            </LinearGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Border x:Name="DropDownBorder"
                            SnapsToDevicePixels="True"
                            Background="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BackgroundBrush}"
                            BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BorderBrush}"
                            BorderThickness="1"
                            CornerRadius="2,2,1,1"
                            Grid.ColumnSpan="1"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch">
                        <Grid Width="Auto"
                              Height="Auto"
                              HorizontalAlignment="Stretch"
                              VerticalAlignment="Stretch">
                            <Border VerticalAlignment="Stretch"
                                    Width="Auto"
                                    Height="Auto"
                                    BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BackgroundBrush}"
                                    BorderThickness="1"
                                    CornerRadius="1" />
                            <Grid Margin="1"
                                  HorizontalAlignment="Stretch"
                                  VerticalAlignment="Stretch">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Path Fill="{x:Null}"
                                      Stretch="Fill"
                                      Stroke="{DynamicResource Fluent.Ribbon.Brushes.Separator.BorderBrush}"
                                      HorizontalAlignment="Left"
                                      Margin="24,0,0,0"
                                      Width="1"
                                      Height="Auto"
                                      Data="M0,0L0,1"
                                      Grid.RowSpan="2"
                                      Visibility="Visible" />
                                <ScrollViewer VerticalScrollBarVisibility="Auto"
                                              x:Name="PART_ScrollViewer"
                                              Margin="1"
                                              SnapsToDevicePixels="True">
                                    <StackPanel x:Name="PART_MenuPanel"
                                                MaxWidth="{Binding ActualWidth, ElementName=PART_ScrollViewer}"
                                                Orientation="Vertical"
                                                IsItemsHost="True"
                                                KeyboardNavigation.DirectionalNavigation="Contained" />
                                </ScrollViewer>
                            </Grid>
                        </Grid>
                    </Border>
                </Grid>
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked"
                     Value="True">
                <Setter Property="Visibility"
                        TargetName="rectangle"
                        Value="Visible" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Icon"
                               Value="{x:Null}" />
                    <Condition Property="IsChecked"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="image"
                        Value="Visible" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsHighlighted"
                               Value="True" />
                    <Condition Property="IsEnabled"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="border"
                        Value="Visible" />
            </MultiTrigger>
            <Trigger Property="IsEnabled"
                     Value="False">
                <Setter Property="Opacity"
                        TargetName="iconImage"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="image"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="textBlock"
                        Value="0.5" />
                <Setter Property="Effect"
                        TargetName="iconImage">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
                <Setter Property="Effect"
                        TargetName="image">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!--Splited Menu Item Template-->
    <ControlTemplate x:Key="SplitedApplicationMenuSecondLevelItemTemplate"
                     TargetType="{x:Type Fluent:MenuItem}">
        <ControlTemplate.Resources>
            <ResourceDictionary>
                <Style x:Key="{x:Type ScrollViewer}"
                       TargetType="{x:Type ScrollViewer}"
                       BasedOn="{StaticResource MenuScrollViewer}" />
            </ResourceDictionary>
        </ControlTemplate.Resources>
        <Grid Width="Auto"
              MinHeight="53"
              Height="Auto"
              Background="Transparent">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="44" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Rectangle Grid.Column="2"
                       HorizontalAlignment="Right"
                       Margin="0,4,23,4"
                       Stroke="{DynamicResource Fluent.Ribbon.Brushes.Separator.BorderBrush}"
                       Width="1" />

            <Grid  HorizontalAlignment="Stretch"
                   Margin="0"
                   Width="Auto"
                   Grid.Column="0"
                   Grid.ColumnSpan="3">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0.905*" />
                    <ColumnDefinition x:Name="columnDefinition"
                                      Width="23" />
                </Grid.ColumnDefinitions>
                <Border x:Name="PART_ButtonBorder"
                        Visibility="Collapsed"
                        Background="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.Background}"
                        BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.BorderBrush}"
                        BorderThickness="1"
                        CornerRadius="2"
                        Margin="0,0,-1,0" />
                <Border x:Name="Submenu_Border"
                        HorizontalAlignment="Stretch"
                        Margin="0"
                        Width="Auto"
                        Visibility="Collapsed"
                        Background="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.Background}"
                        BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.BorderBrush}"
                        BorderThickness="1"
                        CornerRadius="2"
                        Grid.Column="1" />
            </Grid>
            <TextBlock x:Name="textBlock"
                       FontWeight="Bold"
                       Text="{TemplateBinding Header}"
                       Width="Auto"
                       Height="Auto"
                       Margin="9,5,3,3"
                       VerticalAlignment="Top"
                       Grid.Column="1"
                       d:LayoutOverrides="Width"
                       TextTrimming="CharacterEllipsis" />
            <TextBlock x:Name="textBlockDesc"
                       Text="{TemplateBinding Description}"
                       Width="Auto"
                       HorizontalAlignment="Stretch"
                       Height="Auto"
                       Margin="9,22,3,3"
                       VerticalAlignment="Top"
                       Grid.Column="1"
                       d:LayoutOverrides="Width"
                       TextWrapping="Wrap" />
            <Rectangle x:Name="rectangle"
                       Fill="{DynamicResource Fluent.Ribbon.Brushes.ApplicationMenuItem.CheckBox.Background}"
                       Stroke="{DynamicResource Fluent.Ribbon.Brushes.ApplicationMenuItem.CheckBox.BorderBrush}"
                       Grid.ColumnSpan="1"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center"
                       Width="40"
                       Height="40"
                       RadiusX="1"
                       RadiusY="1"
                       Visibility="Collapsed" />
            <Image x:Name="image"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Top"
                   Margin="0,4,0,0"
                   Width="32"
                   Height="32"
                   Stretch="Uniform"
                   Source="{DynamicResource Fluent.Ribbon.Images.Checked}"
                   Visibility="Collapsed"
                   SnapsToDevicePixels="True" />
            <ContentPresenter x:Name="iconImage"
                              HorizontalAlignment="Center"
                              Height="32"
                              VerticalAlignment="Top"
                              Margin="3,4,2,2"
                              Content="{converters:ObjectToImageConverter {Binding Icon, RelativeSource={RelativeSource TemplatedParent}}, '32,32', {Binding RelativeSource={RelativeSource TemplatedParent}}}"
                              Width="32"
                              SnapsToDevicePixels="True" />
            <Path x:Name="path"
                  Stretch="Fill"
                  Stroke="{x:Null}"
                  HorizontalAlignment="Right"
                  Margin="1,0,9,0"
                  Width="4"
                  Data="M0,0L1,1 0,2z"
                  Height="7"
                  Grid.Column="3"
                  Fill="{DynamicResource Fluent.Ribbon.MenuItem.SubMenu.Arrow.Fill}" />
            <Popup x:Name="PART_Popup"
                   Placement="Right"
                   IsOpen="{TemplateBinding IsSubmenuOpen}"
                   AllowsTransparency="True"
                   Focusable="False"
                   PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
                   Margin="0,0,-4,0"
                   VerticalAlignment="Top"
                   Grid.ColumnSpan="2">
                <Grid x:Name="DropDown"
                      SnapsToDevicePixels="True"
                      Margin="0"
                      VerticalAlignment="Stretch">
                    <Border x:Name="DropDownBorder"
                            SnapsToDevicePixels="True"
                            Background="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BackgroundBrush}"
                            BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BorderBrush}"
                            BorderThickness="1"
                            CornerRadius="1"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch">
                        <Grid Width="Auto"
                              Height="Auto"
                              HorizontalAlignment="Stretch"
                              VerticalAlignment="Stretch">
                            <Border VerticalAlignment="Stretch"
                                    Width="Auto"
                                    Height="Auto"
                                    BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BackgroundBrush}"
                                    BorderThickness="1"
                                    CornerRadius="1" />
                            <Grid Margin="1"
                                  HorizontalAlignment="Stretch"
                                  VerticalAlignment="Stretch">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Path Fill="{x:Null}"
                                      Stretch="Fill"
                                      Stroke="{DynamicResource Fluent.Ribbon.Brushes.Separator.BorderBrush}"
                                      HorizontalAlignment="Left"
                                      Margin="24,0,0,0"
                                      Width="1"
                                      Height="Auto"
                                      Data="M0,0L0,1"
                                      Grid.RowSpan="2"
                                      Visibility="Visible" />
                                <ScrollViewer Margin="1"
                                              x:Name="PART_ScrollViewer"
                                              Style="{DynamicResource MenuScrollViewer}"
                                              SnapsToDevicePixels="True">
                                    <StackPanel x:Name="PART_MenuPanel"
                                                MaxWidth="{Binding ActualWidth, ElementName=PART_ScrollViewer}"
                                                Orientation="Vertical"
                                                IsItemsHost="True"
                                                KeyboardNavigation.DirectionalNavigation="Contained" />
                                </ScrollViewer>
                            </Grid>
                        </Grid>
                    </Border>
                </Grid>
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked"
                     Value="True">
                <Setter Property="Visibility"
                        TargetName="rectangle"
                        Value="Visible" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Icon"
                               Value="{x:Null}" />
                    <Condition Property="IsChecked"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="image"
                        Value="Visible" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsHighlighted"
                               Value="True" />
                    <Condition Property="IsEnabled"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="PART_ButtonBorder"
                        Value="Visible" />
                <Setter Property="Visibility"
                        TargetName="Submenu_Border"
                        Value="Visible" />
            </MultiTrigger>
            <Trigger Property="IsSubmenuOpen"
                     Value="True">
                <Setter Property="Background"
                        TargetName="Submenu_Border"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.Pressed.Background}" />
            </Trigger>
            <Trigger Property="IsEnabled"
                     Value="False">
                <Setter Property="Opacity"
                        TargetName="iconImage"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="image"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="textBlock"
                        Value="0.5" />
                <Setter Property="Effect"
                        TargetName="iconImage">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
                <Setter Property="Effect"
                        TargetName="image">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!--Menu Item Style-->
    <Style x:Key="Fluent.Ribbon.Styles.ApplicationMenu.MenuItemSecondLevel"
           TargetType="{x:Type Fluent:MenuItem}">
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
                Value="Hidden" />
        <Setter Property="Foreground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.LabelTextBrush}" />
        <Setter Property="ResizeMode"
                Value="None" />
        <Setter Property="SnapsToDevicePixels"
                Value="True" />
        <Setter Property="OverridesDefaultStyle"
                Value="True" />
        <Setter Property="Template"
                Value="{DynamicResource ApplicationMenuSecondLevelItemTemplate}" />
        <Style.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Fluent:MenuItem.IsSplited"
                               Value="True" />
                    <Condition Property="HasItems"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Template"
                        Value="{DynamicResource SplitedApplicationMenuSecondLevelItemTemplate}" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Fluent:MenuItem.IsSplited"
                               Value="False" />
                    <Condition Property="HasItems"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Template"
                        Value="{DynamicResource HeaderApplicationMenuSecondLevelItemTemplate}" />
            </MultiTrigger>
        </Style.Triggers>
    </Style>

    <!-- First Level-->
    <!--Menu Item Template-->
    <ControlTemplate x:Key="ApplicationMenuItemTemplate"
                     TargetType="{x:Type Fluent:MenuItem}">
        <ControlTemplate.Resources>
            <ResourceDictionary>
                <Style x:Key="{x:Type ScrollViewer}"
                       TargetType="{x:Type ScrollViewer}"
                       BasedOn="{StaticResource MenuScrollViewer}" />
            </ResourceDictionary>
        </ControlTemplate.Resources>
        <Grid Width="Auto"
              Height="44"
              Background="Transparent">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="44" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Border x:Name="border"
                    HorizontalAlignment="Stretch"
                    Margin="0"
                    Width="Auto"
                    Visibility="Collapsed"
                    Background="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.Background}"
                    BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.BorderBrush}"
                    BorderThickness="1"
                    CornerRadius="2"
                    Grid.Column="0"
                    Grid.ColumnSpan="3" />
            <TextBlock x:Name="textBlock"
                       Text="{TemplateBinding Header}"
                       Width="Auto"
                       Height="Auto"
                       Margin="9,3,3,3"
                       VerticalAlignment="Center"
                       Grid.Column="1"
                       d:LayoutOverrides="Width"
                       TextTrimming="CharacterEllipsis" />
            <TextBlock x:Name="textBlockDesc"
                       Text="{TemplateBinding Description}"
                       Width="Auto"
                       HorizontalAlignment="Right"
                       Height="Auto"
                       Margin="0,3,3,3"
                       VerticalAlignment="Center"
                       Grid.Column="2"
                       d:LayoutOverrides="Width"
                       TextWrapping="NoWrap" />
            <Rectangle x:Name="rectangle"
                       Fill="{DynamicResource Fluent.Ribbon.Brushes.ApplicationMenuItem.CheckBox.Background}"
                       Stroke="{DynamicResource Fluent.Ribbon.Brushes.ApplicationMenuItem.CheckBox.BorderBrush}"
                       Grid.ColumnSpan="1"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center"
                       Width="40"
                       Height="40"
                       RadiusX="1"
                       RadiusY="1"
                       Visibility="Collapsed" />
            <Image x:Name="image"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   Width="32"
                   Height="32"
                   Stretch="Uniform"
                   Source="{DynamicResource Fluent.Ribbon.Images.Checked}"
                   Visibility="Collapsed"
                   SnapsToDevicePixels="True" />
            <ContentPresenter x:Name="iconImage"
                              HorizontalAlignment="Center"
                              Height="32"
                              VerticalAlignment="Center"
                              Content="{converters:ObjectToImageConverter {Binding Icon, RelativeSource={RelativeSource TemplatedParent}}, '32,32', {Binding RelativeSource={RelativeSource TemplatedParent}}}"
                              Width="32"
                              Margin="3,2,2,2"
                              SnapsToDevicePixels="True" />
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked"
                     Value="True">
                <Setter Property="Visibility"
                        TargetName="rectangle"
                        Value="Visible" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Icon"
                               Value="{x:Null}" />
                    <Condition Property="IsChecked"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="image"
                        Value="Visible" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsHighlighted"
                               Value="True" />
                    <Condition Property="IsEnabled"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="border"
                        Value="Visible" />
            </MultiTrigger>
            <Trigger Property="IsEnabled"
                     Value="False">
                <Setter Property="Opacity"
                        TargetName="iconImage"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="image"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="textBlock"
                        Value="0.5" />
                <Setter Property="Effect"
                        TargetName="iconImage">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
                <Setter Property="Effect"
                        TargetName="image">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!--Header Menu Item Template-->
    <ControlTemplate x:Key="HeaderApplicationMenuItemTemplate"
                     TargetType="{x:Type Fluent:MenuItem}">
        <ControlTemplate.Resources>
            <ResourceDictionary>
                <Style x:Key="{x:Type ScrollViewer}"
                       TargetType="{x:Type ScrollViewer}"
                       BasedOn="{StaticResource MenuScrollViewer}" />
            </ResourceDictionary>
        </ControlTemplate.Resources>
        <Grid Width="Auto"
              Height="44"
              Background="Transparent">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="44" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Border x:Name="border"
                    HorizontalAlignment="Stretch"
                    Margin="0"
                    Width="Auto"
                    Visibility="Collapsed"
                    Background="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.Background}"
                    BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.BorderBrush}"
                    BorderThickness="1"
                    CornerRadius="2"
                    Grid.Column="0"
                    Grid.ColumnSpan="3" />
            <TextBlock x:Name="textBlock"
                       Text="{TemplateBinding Header}"
                       Width="Auto"
                       Height="Auto"
                       Margin="9,3,3,3"
                       VerticalAlignment="Center"
                       Grid.Column="1"
                       d:LayoutOverrides="Width"
                       TextTrimming="CharacterEllipsis" />
            <Rectangle x:Name="rectangle"
                       Fill="{DynamicResource Fluent.Ribbon.Brushes.ApplicationMenuItem.CheckBox.Background}"
                       Stroke="{DynamicResource Fluent.Ribbon.Brushes.ApplicationMenuItem.CheckBox.BorderBrush}"
                       Grid.ColumnSpan="1"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center"
                       Width="40"
                       Height="40"
                       RadiusX="1"
                       RadiusY="1"
                       Visibility="Collapsed" />
            <Image x:Name="image"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   Width="32"
                   Height="32"
                   Stretch="Uniform"
                   Source="{DynamicResource Fluent.Ribbon.Images.Checked}"
                   Visibility="Collapsed"
                   SnapsToDevicePixels="True" />
            <ContentPresenter x:Name="iconImage"
                              HorizontalAlignment="Center"
                              Height="32"
                              VerticalAlignment="Center"
                              Content="{converters:ObjectToImageConverter {Binding Icon, RelativeSource={RelativeSource TemplatedParent}}, '32,32', {Binding RelativeSource={RelativeSource TemplatedParent}}}"
                              Width="32"
                              Margin="3,2,2,2"
                              SnapsToDevicePixels="True" />
            <Path x:Name="path"
                  Stretch="Fill"
                  Stroke="{x:Null}"
                  HorizontalAlignment="Right"
                  Margin="1,0,9,0"
                  Width="4"
                  Data="M0,0L1,1 0,2z"
                  Height="7"
                  Grid.Column="3"
                  Fill="{DynamicResource Fluent.Ribbon.MenuItem.SubMenu.Arrow.Fill}" />
            <Popup x:Name="PART_Popup"
                   Placement="Custom"
                   CustomPopupPlacementCallback="{x:Static FluentHelpers:PopupHelper.SimplePlacementCallback}"
                   PlacementTarget="{Binding Converter={StaticResource ApplicationMenuRightScrollViewerExtractorConverter}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:ApplicationMenu}}}"
                   IsOpen="{TemplateBinding IsSubmenuOpen}"
                   AllowsTransparency="True"
                   Focusable="False"
                   PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
                   Margin="0,0,0,0"
                   VerticalAlignment="Top"
                   Grid.ColumnSpan="2"
                   Width="{Binding RightPaneWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:ApplicationMenu}}}"
                   Height="{Binding ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ScrollViewer}}}">
                <Grid Name="DropDown"
                      SnapsToDevicePixels="True"
                      Margin="0"
                      VerticalAlignment="Stretch">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="4" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="4" />
                    </Grid.ColumnDefinitions>
                    <Rectangle HorizontalAlignment="Left"
                               VerticalAlignment="Top"
                               Width="4"
                               Height="4"
                               Grid.Row="1"
                               Grid.Column="1"
                               StrokeThickness="0"
                               Margin="-1,-1,0,0">
                        <Rectangle.Fill>
                            <RadialGradientBrush RadiusX="0.984"
                                                 Center="0.017,0.002"
                                                 GradientOrigin="0.017,0.002"
                                                 RadiusY="1">
                                <GradientStop Color="#3F000000"
                                              Offset="0" />
                                <GradientStop Color="Transparent"
                                              Offset="1" />
                            </RadialGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle StrokeThickness="0"
                               HorizontalAlignment="Left"
                               Margin="-1,3,0,0"
                               VerticalAlignment="Top"
                               Width="4"
                               Height="4"
                               Grid.Column="1"
                               Grid.Row="0">
                        <Rectangle.Fill>
                            <RadialGradientBrush Center="0.032,1.01"
                                                 GradientOrigin="0.032,1.01"
                                                 RadiusX="0.984"
                                                 RadiusY="1">
                                <GradientStop Color="#3F000000"
                                              Offset="0" />
                                <GradientStop Color="Transparent"
                                              Offset="1" />
                            </RadialGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle StrokeThickness="0"
                               HorizontalAlignment="Left"
                               Margin="3,-1,0,0"
                               VerticalAlignment="Top"
                               Width="4"
                               Height="4"
                               Grid.Column="0"
                               Grid.Row="1">
                        <Rectangle.Fill>
                            <RadialGradientBrush Center="0.996,0.027"
                                                 GradientOrigin="0.996,0.027"
                                                 RadiusX="0.984"
                                                 RadiusY="1">
                                <GradientStop Color="#3F000000"
                                              Offset="0" />
                                <GradientStop Color="Transparent"
                                              Offset="1" />
                            </RadialGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle StrokeThickness="0"
                               HorizontalAlignment="Stretch"
                               Margin="7,-1,1,0"
                               VerticalAlignment="Top"
                               Width="Auto"
                               Height="4"
                               Grid.Column="0"
                               Grid.Row="1">
                        <Rectangle.Fill>
                            <LinearGradientBrush EndPoint="0.5,1"
                                                 StartPoint="0.5,0"
                                                 MappingMode="RelativeToBoundingBox">
                                <GradientStop Color="#3F000000"
                                              Offset="0" />
                                <GradientStop Color="Transparent"
                                              Offset="1" />
                            </LinearGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle StrokeThickness="0"
                               HorizontalAlignment="Left"
                               Margin="-1,7,0,1"
                               VerticalAlignment="Stretch"
                               Width="4"
                               Height="Auto"
                               Grid.Column="1"
                               Grid.Row="0">
                        <Rectangle.Fill>
                            <LinearGradientBrush EndPoint="1,0.5"
                                                 StartPoint="0,0.5"
                                                 MappingMode="RelativeToBoundingBox">
                                <GradientStop Color="#3F000000"
                                              Offset="0" />
                                <GradientStop Color="Transparent"
                                              Offset="1" />
                            </LinearGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Border x:Name="DropDownBorder"
                            SnapsToDevicePixels="True"
                            Background="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BackgroundBrush}"
                            BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BorderBrush}"
                            BorderThickness="1"
                            CornerRadius="2,2,1,1"
                            Grid.ColumnSpan="1"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch">
                        <Grid Width="Auto"
                              Height="Auto"
                              HorizontalAlignment="Stretch"
                              VerticalAlignment="Stretch">
                            <Border VerticalAlignment="Stretch"
                                    Width="Auto"
                                    Height="Auto"
                                    BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BackgroundBrush}"
                                    BorderThickness="1"
                                    CornerRadius="1" />
                            <Grid Margin="1"
                                  HorizontalAlignment="Stretch"
                                  VerticalAlignment="Stretch">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <ScrollViewer VerticalScrollBarVisibility="Auto"
                                              HorizontalScrollBarVisibility="Disabled"
                                              x:Name="PART_ScrollViewer"
                                              Margin="1"
                                              SnapsToDevicePixels="True">
                                    <StackPanel x:Name="PART_MenuPanel"
                                                MaxWidth="{Binding ActualWidth, ElementName=PART_ScrollViewer}"
                                                Orientation="Vertical"
                                                IsItemsHost="True"
                                                KeyboardNavigation.DirectionalNavigation="Contained" />
                                </ScrollViewer>
                            </Grid>
                        </Grid>
                    </Border>
                </Grid>
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked"
                     Value="True">
                <Setter Property="Visibility"
                        TargetName="rectangle"
                        Value="Visible" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Icon"
                               Value="{x:Null}" />
                    <Condition Property="IsChecked"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="image"
                        Value="Visible" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsHighlighted"
                               Value="True" />
                    <Condition Property="IsEnabled"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="border"
                        Value="Visible" />
            </MultiTrigger>
            <Trigger Property="IsEnabled"
                     Value="False">
                <Setter Property="Opacity"
                        TargetName="iconImage"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="image"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="textBlock"
                        Value="0.5" />
                <Setter Property="Effect"
                        TargetName="iconImage">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
                <Setter Property="Effect"
                        TargetName="image">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!--Splited Menu Item Template-->
    <ControlTemplate x:Key="SplitedApplicationMenuItemTemplate"
                     TargetType="{x:Type Fluent:MenuItem}">
        <ControlTemplate.Resources>
            <ResourceDictionary>
                <Style x:Key="{x:Type ScrollViewer}"
                       TargetType="{x:Type ScrollViewer}"
                       BasedOn="{StaticResource MenuScrollViewer}" />
            </ResourceDictionary>
        </ControlTemplate.Resources>
        <Grid Width="Auto"
              Height="44"
              Background="Transparent">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="44" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Rectangle Grid.Column="2"
                       HorizontalAlignment="Right"
                       Margin="0,4,23,4"
                       Stroke="{DynamicResource Fluent.Ribbon.Brushes.Separator.BorderBrush}"
                       Width="1" />

            <Grid  HorizontalAlignment="Stretch"
                   Margin="0"
                   Width="Auto"
                   Grid.Column="0"
                   Grid.ColumnSpan="3">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0.905*" />
                    <ColumnDefinition x:Name="columnDefinition"
                                      Width="23" />
                </Grid.ColumnDefinitions>
                <Border x:Name="PART_ButtonBorder"
                        Visibility="Collapsed"
                        Background="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.Background}"
                        BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.BorderBrush}"
                        BorderThickness="1"
                        CornerRadius="2"
                        Margin="0,0,-1,0" />
                <Border x:Name="Submenu_Border"
                        HorizontalAlignment="Stretch"
                        Margin="0"
                        Width="Auto"
                        Visibility="Collapsed"
                        Background="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.Background}"
                        BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.BorderBrush}"
                        BorderThickness="1"
                        CornerRadius="2"
                        Grid.Column="1" />
            </Grid>
            <TextBlock x:Name="textBlock"
                       Text="{TemplateBinding Header}"
                       Width="Auto"
                       Height="Auto"
                       Margin="9,3,3,3"
                       VerticalAlignment="Center"
                       Grid.Column="1"
                       d:LayoutOverrides="Width"
                       TextTrimming="CharacterEllipsis" />
            <Rectangle x:Name="rectangle"
                       Fill="{DynamicResource Fluent.Ribbon.Brushes.ApplicationMenuItem.CheckBox.Background}"
                       Stroke="{DynamicResource Fluent.Ribbon.Brushes.ApplicationMenuItem.CheckBox.BorderBrush}"
                       Grid.ColumnSpan="1"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center"
                       Width="40"
                       Height="40"
                       RadiusX="1"
                       RadiusY="1"
                       Visibility="Collapsed" />
            <Image x:Name="image"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   Width="32"
                   Height="32"
                   Stretch="Uniform"
                   Source="{DynamicResource Fluent.Ribbon.Images.Checked}"
                   Visibility="Collapsed"
                   SnapsToDevicePixels="True" />
            <ContentPresenter x:Name="iconImage"
                              HorizontalAlignment="Center"
                              Height="32"
                              VerticalAlignment="Center"
                              Content="{converters:ObjectToImageConverter {Binding Icon, RelativeSource={RelativeSource TemplatedParent}}, '32,32', {Binding RelativeSource={RelativeSource TemplatedParent}}}"
                              Width="32"
                              Margin="3,2,2,2"
                              SnapsToDevicePixels="True" />
            <Path x:Name="path"
                  Stretch="Fill"
                  Stroke="{x:Null}"
                  HorizontalAlignment="Right"
                  Margin="1,0,9,0"
                  Width="4"
                  Data="M0,0L1,1 0,2z"
                  Height="7"
                  Grid.Column="3"
                  Fill="{DynamicResource Fluent.Ribbon.MenuItem.SubMenu.Arrow.Fill}" />
            <Popup x:Name="PART_Popup"
                   Placement="Custom"
                   CustomPopupPlacementCallback="{x:Static FluentHelpers:PopupHelper.SimplePlacementCallback}"
                   PlacementTarget="{Binding Converter={StaticResource ApplicationMenuRightScrollViewerExtractorConverter}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:ApplicationMenu}}}"
                   IsOpen="{TemplateBinding IsSubmenuOpen}"
                   AllowsTransparency="True"
                   Focusable="False"
                   PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
                   Margin="0,0,0,0"
                   VerticalAlignment="Top"
                   Grid.ColumnSpan="2"
                   Width="{Binding RightPaneWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:ApplicationMenu}}}"
                   Height="{Binding ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ScrollViewer}}}">
                <Grid x:Name="DropDown"
                      SnapsToDevicePixels="True"
                      Margin="0"
                      VerticalAlignment="Stretch">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="4" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="4" />
                    </Grid.ColumnDefinitions>
                    <Rectangle HorizontalAlignment="Left"
                               VerticalAlignment="Top"
                               Width="4"
                               Height="4"
                               Grid.Row="1"
                               Grid.Column="1"
                               StrokeThickness="0"
                               Margin="-1,-1,0,0">
                        <Rectangle.Fill>
                            <RadialGradientBrush RadiusX="0.984"
                                                 Center="0.017,0.002"
                                                 GradientOrigin="0.017,0.002"
                                                 RadiusY="1">
                                <GradientStop Color="#3F000000"
                                              Offset="0" />
                                <GradientStop Color="Transparent"
                                              Offset="1" />
                            </RadialGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle StrokeThickness="0"
                               HorizontalAlignment="Left"
                               Margin="-1,3,0,0"
                               VerticalAlignment="Top"
                               Width="4"
                               Height="4"
                               Grid.Column="1"
                               Grid.Row="0">
                        <Rectangle.Fill>
                            <RadialGradientBrush Center="0.032,1.01"
                                                 GradientOrigin="0.032,1.01"
                                                 RadiusX="0.984"
                                                 RadiusY="1">
                                <GradientStop Color="#3F000000"
                                              Offset="0" />
                                <GradientStop Color="Transparent"
                                              Offset="1" />
                            </RadialGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle StrokeThickness="0"
                               HorizontalAlignment="Left"
                               Margin="3,-1,0,0"
                               VerticalAlignment="Top"
                               Width="4"
                               Height="4"
                               Grid.Column="0"
                               Grid.Row="1">
                        <Rectangle.Fill>
                            <RadialGradientBrush Center="0.996,0.027"
                                                 GradientOrigin="0.996,0.027"
                                                 RadiusX="0.984"
                                                 RadiusY="1">
                                <GradientStop Color="#3F000000"
                                              Offset="0" />
                                <GradientStop Color="Transparent"
                                              Offset="1" />
                            </RadialGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle StrokeThickness="0"
                               HorizontalAlignment="Stretch"
                               Margin="7,-1,1,0"
                               VerticalAlignment="Top"
                               Width="Auto"
                               Height="4"
                               Grid.Column="0"
                               Grid.Row="1">
                        <Rectangle.Fill>
                            <LinearGradientBrush EndPoint="0.5,1"
                                                 StartPoint="0.5,0"
                                                 MappingMode="RelativeToBoundingBox">
                                <GradientStop Color="#3F000000"
                                              Offset="0" />
                                <GradientStop Color="Transparent"
                                              Offset="1" />
                            </LinearGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Rectangle StrokeThickness="0"
                               HorizontalAlignment="Left"
                               Margin="-1,7,0,1"
                               VerticalAlignment="Stretch"
                               Width="4"
                               Height="Auto"
                               Grid.Column="1"
                               Grid.Row="0">
                        <Rectangle.Fill>
                            <LinearGradientBrush EndPoint="1,0.5"
                                                 StartPoint="0,0.5"
                                                 MappingMode="RelativeToBoundingBox">
                                <GradientStop Color="#3F000000"
                                              Offset="0" />
                                <GradientStop Color="Transparent"
                                              Offset="1" />
                            </LinearGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <Border x:Name="DropDownBorder"
                            SnapsToDevicePixels="True"
                            Background="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BackgroundBrush}"
                            BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BorderBrush}"
                            BorderThickness="1"
                            CornerRadius="1"
                            Grid.ColumnSpan="1"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch">
                        <Grid Width="Auto"
                              Height="Auto"
                              HorizontalAlignment="Stretch"
                              VerticalAlignment="Stretch">
                            <Border VerticalAlignment="Stretch"
                                    Width="Auto"
                                    Height="Auto"
                                    BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BackgroundBrush}"
                                    BorderThickness="1"
                                    CornerRadius="1" />
                            <Grid Margin="1"
                                  HorizontalAlignment="Stretch"
                                  VerticalAlignment="Stretch">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <ScrollViewer Margin="1"
                                              x:Name="PART_ScrollViewer"
                                              Style="{DynamicResource MenuScrollViewer}"
                                              SnapsToDevicePixels="True">
                                    <StackPanel x:Name="PART_MenuPanel"
                                                MaxWidth="{Binding ActualWidth, ElementName=PART_ScrollViewer}"
                                                Orientation="Vertical"
                                                IsItemsHost="True"
                                                KeyboardNavigation.DirectionalNavigation="Contained" />
                                </ScrollViewer>

                            </Grid>
                        </Grid>
                    </Border>
                </Grid>
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked"
                     Value="True">
                <Setter Property="Visibility"
                        TargetName="rectangle"
                        Value="Visible" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Icon"
                               Value="{x:Null}" />
                    <Condition Property="IsChecked"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="image"
                        Value="Visible" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsHighlighted"
                               Value="True" />
                    <Condition Property="IsEnabled"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="PART_ButtonBorder"
                        Value="Visible" />
                <Setter Property="Visibility"
                        TargetName="Submenu_Border"
                        Value="Visible" />
            </MultiTrigger>
            <Trigger Property="IsSubmenuOpen"
                     Value="True">
                <Setter Property="Background"
                        TargetName="Submenu_Border"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.Pressed.Background}" />
            </Trigger>
            <Trigger Property="IsEnabled"
                     Value="False">
                <Setter Property="Opacity"
                        TargetName="iconImage"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="image"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="textBlock"
                        Value="0.5" />
                <Setter Property="Effect"
                        TargetName="iconImage">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
                <Setter Property="Effect"
                        TargetName="image">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!--Menu Item Style-->
    <Style x:Key="Fluent.Ribbon.Styles.ApplicationMenu.MenuItem"
           TargetType="{x:Type Fluent:MenuItem}">
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
                Value="Hidden" />
        <Setter Property="Foreground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.LabelTextBrush}" />
        <Setter Property="ResizeMode"
                Value="None" />
        <Setter Property="SnapsToDevicePixels"
                Value="True" />
        <Setter Property="OverridesDefaultStyle"
                Value="True" />
        <Setter Property="Template"
                Value="{DynamicResource ApplicationMenuItemTemplate}" />
        <Style.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Fluent:MenuItem.IsSplited"
                               Value="True" />
                    <Condition Property="HasItems"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Template"
                        Value="{DynamicResource SplitedApplicationMenuItemTemplate}" />
                <Setter Property="ItemContainerStyleSelector" 
                        Value="{x:Static styleSelectors:SplitedApplicationMenuItemItemContainerStyleSelector.Instance}" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Fluent:MenuItem.IsSplited"
                               Value="False" />
                    <Condition Property="HasItems"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Template"
                        Value="{DynamicResource HeaderApplicationMenuItemTemplate}" />
                <Setter Property="ItemContainerStyleSelector" 
                        Value="{x:Static styleSelectors:HeaderApplicationMenuItemItemContainerStyleSelector.Instance}" />
            </MultiTrigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>