<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:Fluent="clr-namespace:Fluent"
                    xmlns:converters="clr-namespace:Fluent.Converters"
                    mc:Ignorable="d">
    <ControlTemplate x:Key="ResizeBothThumbControlTemplate"
                     TargetType="{x:Type Thumb}">
        <Grid Background="Transparent">
            <Rectangle Fill="{DynamicResource WhiteBrush}"
                       StrokeThickness="0"
                       Width="2"
                       Height="2"
                       VerticalAlignment="Bottom"
                       HorizontalAlignment="Right"
                       Margin="0,0,2,1" />
            <Rectangle Fill="{DynamicResource WhiteBrush}"
                       StrokeThickness="0"
                       HorizontalAlignment="Right"
                       Margin="0,0,2,5"
                       VerticalAlignment="Bottom"
                       Width="2"
                       Height="2" />
            <Rectangle Fill="{DynamicResource WhiteBrush}"
                       StrokeThickness="0"
                       HorizontalAlignment="Right"
                       Margin="0,0,6,1"
                       VerticalAlignment="Bottom"
                       Width="2"
                       Height="2" />
            <Rectangle Fill="{DynamicResource BlackBrush}"
                       StrokeThickness="0"
                       HorizontalAlignment="Right"
                       Margin="0,0,3,2"
                       VerticalAlignment="Bottom"
                       Width="2"
                       Height="2" />
            <Rectangle Fill="{DynamicResource BlackBrush}"
                       StrokeThickness="0"
                       HorizontalAlignment="Right"
                       Margin="0,0,3,6"
                       VerticalAlignment="Bottom"
                       Width="2"
                       Height="2" />
            <Rectangle Fill="{DynamicResource BlackBrush}"
                       StrokeThickness="0"
                       HorizontalAlignment="Right"
                       Margin="0,0,7,2"
                       VerticalAlignment="Bottom"
                       Width="2"
                       Height="2" />
        </Grid>
    </ControlTemplate>

    <ControlTemplate x:Key="ResizeVerticalThumbControlTemplate"
                     TargetType="{x:Type Thumb}">
        <Grid Background="Transparent">
            <StackPanel Margin="0,1,0,0"
                        Orientation="Horizontal"
                        d:LayoutOverrides="Height"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center">
                <Grid HorizontalAlignment="Left"
                      Margin="1,0,0,0"
                      Width="Auto"
                      Height="Auto">
                    <Rectangle Fill="{DynamicResource WhiteBrush}"
                               StrokeThickness="0"
                               HorizontalAlignment="Center"
                               Margin="0"
                               VerticalAlignment="Center"
                               Width="2"
                               Height="2" />
                    <Rectangle Fill="{DynamicResource BlackBrush}"
                               StrokeThickness="0"
                               HorizontalAlignment="Center"
                               Margin="0,0,1,1"
                               VerticalAlignment="Center"
                               Width="2"
                               Height="2" />
                </Grid>
                <Grid HorizontalAlignment="Left"
                      Margin="1,0,0,0"
                      Width="Auto"
                      Height="Auto">
                    <Rectangle Fill="{DynamicResource WhiteBrush}"
                               StrokeThickness="0"
                               HorizontalAlignment="Center"
                               Margin="0"
                               VerticalAlignment="Center"
                               Width="2"
                               Height="2" />
                    <Rectangle Fill="{DynamicResource BlackBrush}"
                               StrokeThickness="0"
                               HorizontalAlignment="Center"
                               Margin="0,0,1,1"
                               VerticalAlignment="Center"
                               Width="2"
                               Height="2" />
                </Grid>
                <Grid HorizontalAlignment="Left"
                      Margin="1,0,0,0"
                      Width="Auto"
                      Height="Auto">
                    <Rectangle Fill="{DynamicResource WhiteBrush}"
                               StrokeThickness="0"
                               HorizontalAlignment="Center"
                               Margin="0"
                               VerticalAlignment="Center"
                               Width="2"
                               Height="2" />
                    <Rectangle Fill="{DynamicResource BlackBrush}"
                               StrokeThickness="0"
                               HorizontalAlignment="Center"
                               Margin="0,0,1,1"
                               VerticalAlignment="Center"
                               Width="2"
                               Height="2" />
                </Grid>
                <Grid HorizontalAlignment="Left"
                      Margin="1,0,0,0"
                      Width="Auto"
                      Height="Auto">
                    <Rectangle Fill="{DynamicResource WhiteBrush}"
                               StrokeThickness="0"
                               HorizontalAlignment="Center"
                               Margin="0"
                               VerticalAlignment="Center"
                               Width="2"
                               Height="2" />
                    <Rectangle Fill="{DynamicResource BlackBrush}"
                               StrokeThickness="0"
                               HorizontalAlignment="Center"
                               Margin="0,0,1,1"
                               VerticalAlignment="Center"
                               Width="2"
                               Height="2" />
                </Grid>
            </StackPanel>
        </Grid>
    </ControlTemplate>

    <!--Menu Item Template-->
    <ControlTemplate x:Key="MenuItemTemplate"
                     TargetType="{x:Type MenuItem}">
        <Grid Background="{TemplateBinding Background}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="25" />
                <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"
                    Grid.Column="0"
                    Grid.ColumnSpan="3">
            </Border>
            <ContentPresenter x:Name="textBlock"
                              ContentSource="Header"
                              ContentTemplate="{TemplateBinding HeaderTemplate}"
                              ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                              Width="Auto"
                              Height="Auto"
                              Margin="5,3,3,3"
                              VerticalAlignment="Center"
                              Grid.Column="1"
                              d:LayoutOverrides="Width"
                              RecognizesAccessKey="{Binding Path=(Fluent:MenuItem.RecognizesAccessKey), RelativeSource={RelativeSource TemplatedParent}}" />
            <Border x:Name="iconImageBorder"
                    BorderThickness="1">
                <ContentPresenter x:Name="iconImage"
                                  HorizontalAlignment="Center"
                                  Height="16"
                                  VerticalAlignment="Center"
                                  Content="{converters:ObjectToImageConverter {Binding Icon, RelativeSource={RelativeSource TemplatedParent}}, '16,16', {Binding RelativeSource={RelativeSource TemplatedParent}}}"
                                  Width="16"
                                  Margin="3,2,2,2"
                                  SnapsToDevicePixels="True" />
            </Border>
            <Image x:Name="checkedImage"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   Width="16"
                   Height="16"
                   Stretch="Uniform"
                   Source="{DynamicResource Fluent.Ribbon.Images.Checked}"
                   Visibility="Collapsed"
                   SnapsToDevicePixels="True" />
            <TextBlock x:Name="gestureTextBlock"
                       Text="{TemplateBinding InputGestureText}"
                       Width="Auto"
                       Height="Auto"
                       Margin="3,3,15,3"
                       VerticalAlignment="Center"
                       Grid.Column="2" />
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="InputGestureText"
                     Value="{x:Null}">
                <Setter Property="Visibility"
                        TargetName="gestureTextBlock"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="InputGestureText"
                     Value="">
                <Setter Property="Visibility"
                        TargetName="gestureTextBlock"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsChecked"
                     Value="True">
                <Setter Property="Background"
                        TargetName="iconImageBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.ToggleButton.Checked.Background}" />
                <Setter Property="BorderBrush"
                        TargetName="iconImageBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.ToggleButton.Checked.BorderBrush}" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Icon"
                               Value="{x:Null}" />
                    <Condition Property="IsChecked"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="checkedImage"
                        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="checkedImage"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="textBlock"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="gestureTextBlock"
                        Value="0.5" />
                <Setter Property="Effect"
                        TargetName="iconImage">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
                <Setter Property="Effect"
                        TargetName="checkedImage">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!--Header Menu Item Template-->
    <ControlTemplate x:Key="HeaderMenuItemTemplate"
                     TargetType="{x:Type MenuItem}">
        <Grid Background="{TemplateBinding Background}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="25" />
                <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"
                    Grid.Column="0"
                    Grid.ColumnSpan="3">
            </Border>
            <ContentPresenter x:Name="textBlock"
                              ContentSource="Header"
                              ContentTemplate="{TemplateBinding HeaderTemplate}"
                              ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                              Width="Auto"
                              Height="Auto"
                              Margin="5,3,3,3"
                              VerticalAlignment="Center"
                              Grid.Column="1"
                              d:LayoutOverrides="Width"
                              RecognizesAccessKey="{Binding Path=(Fluent:MenuItem.RecognizesAccessKey), RelativeSource={RelativeSource TemplatedParent}}" />
            <Border x:Name="iconImageBorder"
                    BorderThickness="1">
                <ContentPresenter x:Name="iconImage"
                                  HorizontalAlignment="Center"
                                  Height="16"
                                  VerticalAlignment="Center"
                                  Content="{converters:ObjectToImageConverter {Binding Icon, RelativeSource={RelativeSource TemplatedParent}}, '16,16', {Binding RelativeSource={RelativeSource TemplatedParent}}}"
                                  Width="16"
                                  Margin="3,2,2,2"
                                  SnapsToDevicePixels="True" />
            </Border>
            <Image x:Name="checkedImage"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   Width="16"
                   Height="16"
                   Stretch="Uniform"
                   Source="{DynamicResource Fluent.Ribbon.Images.Checked}"
                   Visibility="Collapsed"
                   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 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"
                            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" />
                            <Grid Margin="1"
                                  HorizontalAlignment="Stretch"
                                  VerticalAlignment="Stretch">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <ScrollViewer x:Name="PART_ScrollViewer"
                                              Style="{DynamicResource MenuScrollViewer}"
                                              Margin="1"
                                              SnapsToDevicePixels="True">
                                    <StackPanel x:Name="PART_MenuPanel"
                                                Orientation="Vertical"
                                                IsItemsHost="True"
                                                KeyboardNavigation.DirectionalNavigation="Contained" />
                                </ScrollViewer>
                                <Border x:Name="resizeBorder"
                                        HorizontalAlignment="Stretch"
                                        VerticalAlignment="Top"
                                        Height="11"
                                        BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.DropDown.Resize.BorderBrush}"
                                        BorderThickness="0,1,0,0"
                                        Grid.Row="1"
                                        Background="{DynamicResource Fluent.Ribbon.Brushes.DropDown.Resize.BackgroundBrush}">
                                    <Grid>
                                        <Thumb x:Name="PART_ResizeVerticalThumb"
                                               HorizontalAlignment="Stretch"
                                               Margin="0,0,0,-90"
                                               Width="Auto"
                                               Height="10"
                                               VerticalAlignment="Top"
                                               Cursor="SizeNS"
                                               Template="{DynamicResource ResizeVerticalThumbControlTemplate}" />
                                        <Thumb x:Name="PART_ResizeBothThumb"
                                               HorizontalAlignment="Right"
                                               Margin="0,0,0,-90"
                                               Width="10"
                                               Height="10"
                                               VerticalAlignment="Top"
                                               Cursor="SizeNWSE"
                                               Template="{DynamicResource ResizeBothThumbControlTemplate}" />
                                    </Grid>
                                </Border>
                            </Grid>
                        </Grid>
                    </Border>
                </Grid>
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="Fluent:MenuItem.ResizeMode"
                     Value="None">
                <Setter Property="Visibility"
                        TargetName="resizeBorder"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="Fluent:MenuItem.ResizeMode"
                     Value="Both">
                <Setter Property="Visibility"
                        TargetName="PART_ResizeVerticalThumb"
                        Value="Collapsed" />
                <Setter Property="Visibility"
                        TargetName="PART_ResizeBothThumb"
                        Value="Visible" />
                <Setter Property="Visibility"
                        TargetName="resizeBorder"
                        Value="Visible" />
            </Trigger>
            <Trigger Property="Fluent:MenuItem.ResizeMode"
                     Value="Vertical">
                <Setter Property="Visibility"
                        TargetName="PART_ResizeBothThumb"
                        Value="Collapsed" />
                <Setter Property="Visibility"
                        TargetName="PART_ResizeVerticalThumb"
                        Value="Visible" />
                <Setter Property="Visibility"
                        TargetName="resizeBorder"
                        Value="Visible" />
            </Trigger>
            <Trigger Property="IsChecked"
                     Value="True">
                <Setter Property="Background"
                        TargetName="iconImageBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.ToggleButton.Checked.Background}" />
                <Setter Property="BorderBrush"
                        TargetName="iconImageBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.ToggleButton.Checked.BorderBrush}" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Icon"
                               Value="{x:Null}" />
                    <Condition Property="IsChecked"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="checkedImage"
                        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="checkedImage"
                        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="checkedImage">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!--Splited Menu Item Template-->
    <ControlTemplate x:Key="SplitedMenuItemTemplate"
                     TargetType="{x:Type MenuItem}">
        <Grid Background="{TemplateBinding Background}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="25" />
                <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"
                        Margin="0,0,-1,0">
                </Border>
                <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"
                        Grid.Column="1" />
            </Grid>
            <ContentPresenter x:Name="textBlock"
                              ContentSource="Header"
                              ContentTemplate="{TemplateBinding HeaderTemplate}"
                              ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                              Width="Auto"
                              Height="Auto"
                              Margin="5,3,3,3"
                              VerticalAlignment="Center"
                              Grid.Column="1"
                              d:LayoutOverrides="Width"
                              RecognizesAccessKey="{Binding Path=(Fluent:MenuItem.RecognizesAccessKey), RelativeSource={RelativeSource TemplatedParent}}" />
            <Border x:Name="iconImageBorder"
                    BorderThickness="1">
                <ContentPresenter x:Name="iconImage"
                                  HorizontalAlignment="Center"
                                  Height="16"
                                  VerticalAlignment="Center"
                                  Content="{converters:ObjectToImageConverter {Binding Icon, RelativeSource={RelativeSource TemplatedParent}}, '16,16', {Binding RelativeSource={RelativeSource TemplatedParent}}}"
                                  Width="16"
                                  Margin="3,2,2,2"
                                  SnapsToDevicePixels="True" />
            </Border>
            <Image x:Name="checkedImage"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   Width="16"
                   Height="16"
                   Stretch="Uniform"
                   Source="{DynamicResource Fluent.Ribbon.Images.Checked}"
                   Visibility="Collapsed"
                   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"
                            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}" />
                            <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"
                                                Orientation="Vertical"
                                                IsItemsHost="True"
                                                KeyboardNavigation.DirectionalNavigation="Contained" />
                                </ScrollViewer>
                                <Border x:Name="resizeBorder"
                                        HorizontalAlignment="Stretch"
                                        VerticalAlignment="Top"
                                        Height="11"
                                        BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.DropDown.Resize.BorderBrush}"
                                        BorderThickness="0,1,0,0"
                                        Grid.Row="1"
                                        Background="{DynamicResource Fluent.Ribbon.Brushes.DropDown.Resize.BackgroundBrush}">
                                    <Grid>
                                        <Thumb x:Name="PART_ResizeVerticalThumb"
                                               HorizontalAlignment="Stretch"
                                               Margin="0,0,0,-90"
                                               Width="Auto"
                                               Height="10"
                                               VerticalAlignment="Top"
                                               Cursor="SizeNS"
                                               Template="{DynamicResource ResizeVerticalThumbControlTemplate}" />
                                        <Thumb x:Name="PART_ResizeBothThumb"
                                               HorizontalAlignment="Right"
                                               Margin="0,0,0,-90"
                                               Width="10"
                                               Height="10"
                                               VerticalAlignment="Top"
                                               Cursor="SizeNWSE"
                                               Template="{DynamicResource ResizeBothThumbControlTemplate}" />
                                    </Grid>
                                </Border>
                            </Grid>
                        </Grid>
                    </Border>
                </Grid>
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="Fluent:MenuItem.ResizeMode"
                     Value="None">
                <Setter Property="Visibility"
                        TargetName="resizeBorder"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="Fluent:MenuItem.ResizeMode"
                     Value="Both">
                <Setter Property="Visibility"
                        TargetName="PART_ResizeVerticalThumb"
                        Value="Collapsed" />
                <Setter Property="Visibility"
                        TargetName="PART_ResizeBothThumb"
                        Value="Visible" />
                <Setter Property="Visibility"
                        TargetName="resizeBorder"
                        Value="Visible" />
            </Trigger>
            <Trigger Property="Fluent:MenuItem.ResizeMode"
                     Value="Vertical">
                <Setter Property="Visibility"
                        TargetName="PART_ResizeBothThumb"
                        Value="Collapsed" />
                <Setter Property="Visibility"
                        TargetName="PART_ResizeVerticalThumb"
                        Value="Visible" />
                <Setter Property="Visibility"
                        TargetName="resizeBorder"
                        Value="Visible" />
            </Trigger>
            <Trigger Property="IsChecked"
                     Value="True">
                <Setter Property="Background"
                        TargetName="iconImageBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.ToggleButton.Checked.Background}" />
                <Setter Property="BorderBrush"
                        TargetName="iconImageBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.ToggleButton.Checked.BorderBrush}" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Icon"
                               Value="{x:Null}" />
                    <Condition Property="IsChecked"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="checkedImage"
                        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="checkedImage"
                        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="checkedImage">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!--Menu Item with Description Template-->
    <ControlTemplate x:Key="MenuItemWithDescriptionTemplate"
                     TargetType="{x:Type Fluent:MenuItem}">
        <Grid Background="{TemplateBinding Background}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="45" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Border x:Name="border"
                    Grid.Column="0"
                    Grid.RowSpan="2"
                    Grid.ColumnSpan="3"
                    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">
            </Border>
            <ContentControl x:Name="textBlock"
                            Content="{TemplateBinding Header}"
                            ContentTemplate="{TemplateBinding HeaderTemplate}"
                            ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                            TextElement.FontWeight="Bold"
                            Width="Auto"
                            Height="Auto"
                            Margin="0,3,3,3"
                            VerticalAlignment="Center"
                            Grid.Column="1"
                            d:LayoutOverrides="Width" />
            <ContentPresenter x:Name="descriptionPresenter"
                              Grid.Row="1"
                              ContentSource="Description"
                              Width="Auto"
                              Height="Auto"
                              Margin="0,3,3,3"
                              VerticalAlignment="Center"
                              Grid.Column="1"
                              d:LayoutOverrides="Width"
                              RecognizesAccessKey="{Binding Path=(Fluent:MenuItem.RecognizesAccessKey), RelativeSource={RelativeSource TemplatedParent}}" />
            <Border x:Name="iconImageBorder"
                    BorderThickness="1">
                <ContentPresenter x:Name="iconImage"
                                  HorizontalAlignment="Center"
                                  Height="16"
                                  VerticalAlignment="Center"
                                  Content="{converters:ObjectToImageConverter {Binding Icon, RelativeSource={RelativeSource TemplatedParent}}, '16,16', {Binding RelativeSource={RelativeSource TemplatedParent}}}"
                                  Width="16"
                                  Margin="3,2,2,2"
                                  SnapsToDevicePixels="True" />
            </Border>
            <Image x:Name="checkedImage"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   Width="16"
                   Height="16"
                   Stretch="Uniform"
                   Source="{DynamicResource Fluent.Ribbon.Images.Checked}"
                   Visibility="Collapsed"
                   SnapsToDevicePixels="True" />
            <TextBlock x:Name="gestureTextBlock"
                       Text="{TemplateBinding InputGestureText}"
                       Width="Auto"
                       Height="Auto"
                       Margin="3,3,15,3"
                       VerticalAlignment="Center"
                       Grid.Column="2" />
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="InputGestureText"
                     Value="{x:Null}">
                <Setter Property="Visibility"
                        TargetName="gestureTextBlock"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="InputGestureText"
                     Value="">
                <Setter Property="Visibility"
                        TargetName="gestureTextBlock"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsChecked"
                     Value="True">
                <Setter Property="Background"
                        TargetName="iconImageBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.ToggleButton.Checked.Background}" />
                <Setter Property="BorderBrush"
                        TargetName="iconImageBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.ToggleButton.Checked.BorderBrush}" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Icon"
                               Value="{x:Null}" />
                    <Condition Property="IsChecked"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="checkedImage"
                        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="checkedImage"
                        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="checkedImage">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!--Menu Item Style-->
    <Style x:Key="Fluent.Ribbon.Styles.MenuItem"
           TargetType="{x:Type Fluent:MenuItem}">
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
                Value="Hidden" />
        <Setter Property="Background"
                Value="{DynamicResource Fluent.Ribbon.Brushes.MenuItem.Background}" />
        <Setter Property="Foreground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.LabelTextBrush}" />
        <Setter Property="Template"
                Value="{DynamicResource MenuItemTemplate}" />
        <Style.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Fluent:MenuItem.IsSplited"
                               Value="True" />
                    <Condition Property="HasItems"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Template"
                        Value="{DynamicResource SplitedMenuItemTemplate}" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Fluent:MenuItem.IsSplited"
                               Value="False" />
                    <Condition Property="HasItems"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Template"
                        Value="{DynamicResource HeaderMenuItemTemplate}" />
            </MultiTrigger>
            <DataTrigger Binding="{Binding Description, RelativeSource={RelativeSource Self}, Converter={x:Static converters:IsNullConverter.Instance}}"
                         Value="False">
                <Setter Property="Template"
                        Value="{DynamicResource MenuItemWithDescriptionTemplate}" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>