<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"
                    mc:Ignorable="d">
    <Style x:Key="Fluent.Ribbon.Styles.ContextMenu"
           TargetType="{x:Type Fluent:ContextMenu}">
        <Setter Property="Template"
                Value="{DynamicResource FluentPopupMenuControlTemplate}" />
        <Setter Property="Foreground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.LabelTextBrush}" />
        <Setter Property="MinWidth"
                Value="0" />
        <Setter Property="MinHeight"
                Value="0" />
        <Setter Property="HorizontalAlignment"
                Value="Left" />
        <Setter Property="VerticalAlignment"
                Value="Top" />
    </Style>

    <!-- Default menu style for wpf context menu-->

    <Style x:Key="FluentRibbonDefaultContextMenuStyle"  
           TargetType="{x:Type ContextMenu}">
        <Setter Property="Template"
                Value="{DynamicResource PopupMenuControlTemplate}" />
        <Setter Property="Foreground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.LabelTextBrush}" />
        <Setter Property="MinWidth"
                Value="0" />
        <Setter Property="MinHeight"
                Value="0" />
        <Setter Property="HorizontalAlignment"
                Value="Left" />
        <Setter Property="VerticalAlignment"
                Value="Top" />
    </Style>

    <ControlTemplate x:Key="FluentPopupMenuControlTemplate"
                     TargetType="{x:Type Fluent:ContextMenu}">
        <ControlTemplate.Resources>
            <Style BasedOn="{StaticResource MenuSeparatorStyle}"
                   TargetType="{x:Type Separator}" />
            <Style TargetType="{x:Type Fluent:GroupSeparatorMenuItem}"
                   BasedOn="{StaticResource MenuGroupSeparatorStyle}" />
        </ControlTemplate.Resources>
        <Grid Height="Auto"
              HorizontalAlignment="Left"
              VerticalAlignment="Top">
            <Border SnapsToDevicePixels="True"
                    Background="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BackgroundBrush}"
                    BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BorderBrush}"
                    BorderThickness="1"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Top">
                <Grid Width="Auto"
                      Height="Auto"
                      HorizontalAlignment="Left"
                      VerticalAlignment="Top">
                    <Grid HorizontalAlignment="Left"
                          VerticalAlignment="Top">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <ScrollViewer x:Name="PART_ScrollViewer"
                                      Style="{DynamicResource MenuScrollViewer}"
                                      Margin="1"
                                      SnapsToDevicePixels="True"
                                      VerticalScrollBarVisibility="Auto">
                            <StackPanel IsItemsHost="True"
                                        Orientation="Vertical"
                                        Margin="0"
                                        Width="Auto"
                                        Height="Auto"
                                        x:Name="PART_ItemsHost"
                                        HorizontalAlignment="Left"
                                        VerticalAlignment="Top" />
                        </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>
        <ControlTemplate.Triggers>
            <Trigger Property="FlowDirection"
                     Value="RightToLeft">
                <Setter Property="Cursor"
                        TargetName="PART_ResizeBothThumb"
                        Value="SizeNESW" />
            </Trigger>
            <Trigger Property="ResizeMode"
                     Value="None">
                <Setter Property="Visibility"
                        TargetName="resizeBorder"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="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="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>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="PopupMenuControlTemplate"
                     TargetType="{x:Type ContextMenu}">
        <ControlTemplate.Resources>
            <Style BasedOn="{StaticResource MenuSeparatorStyle}"
                   TargetType="{x:Type Separator}" />
            <Style TargetType="{x:Type Fluent:GroupSeparatorMenuItem}"
                   BasedOn="{StaticResource MenuGroupSeparatorStyle}" />
        </ControlTemplate.Resources>
        <Grid Height="Auto"
              HorizontalAlignment="Left"
              VerticalAlignment="Top">
            <Border SnapsToDevicePixels="True"
                    Background="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BackgroundBrush}"
                    BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BorderBrush}"
                    BorderThickness="1"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Top">
                <Grid Width="Auto"
                      Height="Auto"
                      HorizontalAlignment="Left"
                      VerticalAlignment="Top">
                    <Border VerticalAlignment="Stretch"
                            Width="Auto"
                            Height="Auto"
                            BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BackgroundBrush}"
                            BorderThickness="1" />
                    <Grid HorizontalAlignment="Left"
                          VerticalAlignment="Top">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <ScrollViewer x:Name="PART_ScrollViewer"
                                      Style="{DynamicResource MenuScrollViewer}"
                                      Margin="1"
                                      SnapsToDevicePixels="True"
                                      ScrollViewer.VerticalScrollBarVisibility="Auto">
                            <StackPanel Margin="0"
                                        Width="Auto"
                                        Height="Auto"
                                        IsItemsHost="True"
                                        Grid.RowSpan="1"
                                        x:Name="PART_ItemsHost"
                                        HorizontalAlignment="Left"
                                        VerticalAlignment="Top" />
                        </ScrollViewer>
                    </Grid>
                </Grid>
            </Border>
        </Grid>
    </ControlTemplate>
</ResourceDictionary>