<ResourceDictionary
    xmlns="https://github.com/avaloniaui"
    xmlns:sys="using:System"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ControlTheme TargetType="MenuItem" x:Key="{x:Type MenuItem}">
        <Setter Property="Background" Value="{DynamicResource ContextMenuBackgroundColor}" />
        <Setter Property="Foreground" Value="{DynamicResource ContextMenuTextColor}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="CornerRadius" Value="8" />
        <Setter Property="Padding" Value="6" />
        <Setter Property="Template">
            <ControlTemplate>
                <Border Name="root">
                    <Grid Background="Transparent">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="20" />
                            <ColumnDefinition Width="5" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition SharedSizeGroup="MenuItemIGT" Width="Auto" />
                            <ColumnDefinition Width="20" />
                        </Grid.ColumnDefinitions>
                        <ContentControl
                            Content="{TemplateBinding Icon}"
                            Height="16"
                            HorizontalAlignment="Center"
                            Margin="5,0,0,0"
                            Name="icon"
                            VerticalAlignment="Center"
                            Width="16" />
                        <ContentControl
                            Grid.Column="0"
                            Height="16"
                            IsVisible="True"
                            Margin="5,0,0,0"
                            VerticalAlignment="Center"
                            Width="16"
                            x:Name="PART_ToggleIconPresenter" />
                        <ContentPresenter
                            Content="{TemplateBinding Header}"
                            ContentTemplate="{TemplateBinding HeaderTemplate}"
                            Foreground="{TemplateBinding Foreground}"
                            Grid.Column="2"
                            HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                            Margin="{TemplateBinding Padding}"
                            Name="PART_HeaderPresenter"
                            VerticalAlignment="Center">
                            <ContentPresenter.DataTemplates>
                                <DataTemplate DataType="sys:String">
                                    <AccessText Text="{Binding}" />
                                </DataTemplate>
                            </ContentPresenter.DataTemplates>
                        </ContentPresenter>
                        <Path
                            Data="F1M0.002,31.062L0,0 27.01,15.534z"
                            Fill="{DynamicResource MainTextColor}"
                            Grid.Column="4"
                            Height="8"
                            Margin="6,0,4,0"
                            Name="rightArrow"
                            Stretch="Fill"
                            VerticalAlignment="Center"
                            Width="8" />
                        <Popup
                            Grid.Column="0"
                            IsLightDismissEnabled="False"
                            IsOpen="{TemplateBinding IsSubMenuOpen,
                                                     Mode=TwoWay}"
                            Name="PART_Popup"
                            Placement="RightEdgeAlignedTop">
                            <Border
                                Background="{TemplateBinding Background}"
                                BorderBrush="{DynamicResource MainBorderColor}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="{TemplateBinding CornerRadius}">
                                <ItemsPresenter
                                    Grid.IsSharedSizeScope="True"
                                    ItemsPanel="{TemplateBinding ItemsPanel}"
                                    Margin="2"
                                    Name="PART_ItemsPresenter" />
                            </Border>
                        </Popup>
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter>

        <Style Selector="^:toggle /template/ Viewbox#PART_ToggleIconPresenter, ^:radio /template/ Viewbox#PART_ToggleIconPresenter">
            <Setter Property="IsVisible" Value="True" />
        </Style>
        <Style Selector="^:toggle /template/ ContentPresenter#PART_IconPresenter, ^:radio /template/ ContentPresenter#PART_IconPresenter">
            <Setter Property="IsVisible" Value="False" />
        </Style>
        <Style Selector="^:checked:toggle /template/ ContentControl#PART_ToggleIconPresenter">
            <Setter Property="Content">
                <Template>
                    <Path
                        Data="F1M10,1.2L4.7,9.1 4.5,9.1 0,5.2 1.3,3.5 4.3,6.1 8.3,0 10,1.2z"
                        Fill="{DynamicResource MainTextColor}"
                        VerticalAlignment="Center" />
                </Template>
            </Setter>
        </Style>
        <Style Selector="^:checked:radio /template/ ContentControl#PART_ToggleIconPresenter">
            <Setter Property="Content">
                <Template>
                    <Ellipse
                        Fill="{DynamicResource MainTextColor}"
                        Height="8"
                        Margin="4"
                        Width="8" />
                </Template>
            </Setter>
        </Style>

        <Style Selector="^:not(.noHover):selected /template/ Border#root">
            <Setter Property="Background" Value="{DynamicResource AccentColor}" />
            <Setter Property="BorderBrush" Value="{DynamicResource AccentColor}" />
        </Style>

        <Style Selector="^:not(.noHover):selected /template/ ContentPresenter#PART_HeaderPresenter">
            <Setter Property="Foreground" Value="{StaticResource SecondaryTextColor}" />
            <Setter Property="Effect" Value="{StaticResource TextShadow}" />
        </Style>

        <Style Selector="^:nth-child(1) /template/ Border#root">
            <Setter Property="CornerRadius" Value="6,6,0,0" />
        </Style>

        <Style Selector="^:nth-last-child(1) /template/ Border#root">
            <Setter Property="CornerRadius" Value="0,0,6,6" />
        </Style>

        <Style Selector="^.noCornerRadius:nth-child(1) /template/ Border#root">
            <Setter Property="CornerRadius" Value="0" />
        </Style>

        <Style Selector="^.noCornerRadius:nth-last-child(1) /template/ Border#root">
            <Setter Property="CornerRadius" Value="0" />
        </Style>

        <Style Selector="^:nth-child(1):nth-last-child(1) /template/ Border#root">
            <Setter Property="CornerRadius" Value="0" />
        </Style>

        <Style Selector="^:empty /template/ Path#rightArrow">
            <Setter Property="IsVisible" Value="False" />
        </Style>

        <Style Selector="^:disabled">
            <Setter Property="Opacity" Value="{StaticResource ThemeDisabledOpacity}" />
        </Style>

        <Style Selector="^.active /template/ Border#root">
            <Setter Property="Background" Value="{DynamicResource SecondaryAccentColor}" />
            <Setter Property="BorderBrush" Value="{DynamicResource SecondaryAccentColor}" />
        </Style>

        <Style Selector="^.active /template/ ContentPresenter#PART_HeaderPresenter">
            <Setter Property="Foreground" Value="{StaticResource SecondaryTextColor}" />
            <Setter Property="Effect" Value="{StaticResource TextShadow}" />
        </Style>

    </ControlTheme>

    <ControlTheme TargetType="MenuItem" x:Key="Slim">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Template">
            <ControlTemplate>
                <Border Name="root">
                    <Panel>
                        <ContentPresenter
                            Content="{TemplateBinding Header}"
                            ContentTemplate="{TemplateBinding HeaderTemplate}"
                            Foreground="{DynamicResource ContextMenuTextColor}"
                            Margin="{TemplateBinding Padding}"
                            Name="PART_HeaderPresenter"
                            VerticalAlignment="Center">
                            <ContentPresenter.DataTemplates>
                                <DataTemplate DataType="sys:String">
                                    <AccessText Text="{Binding}" />
                                </DataTemplate>
                            </ContentPresenter.DataTemplates>
                        </ContentPresenter>
                        <Popup
                            IsLightDismissEnabled="False"
                            IsOpen="{TemplateBinding IsSubMenuOpen,
                                                     Mode=TwoWay}"
                            Name="PART_Popup"
                            Placement="RightEdgeAlignedTop">
                            <Border
                                Background="{DynamicResource ContextMenuBackgroundColor}"
                                BorderBrush="{DynamicResource MainBorderColor}"
                                BorderThickness="1"
                                CornerRadius="8">
                                <ItemsPresenter
                                    Grid.IsSharedSizeScope="True"
                                    ItemsPanel="{TemplateBinding ItemsPanel}"
                                    Margin="2"
                                    Name="PART_ItemsPresenter" />
                            </Border>
                        </Popup>
                    </Panel>
                </Border>
            </ControlTemplate>
        </Setter>

    </ControlTheme>

    <ControlTheme TargetType="MenuItem" x:Key="MainBg">
        <Setter Property="Background" Value="{DynamicResource SecondaryBackgroundColor}" />
        <Setter Property="Foreground" Value="{DynamicResource MainTextColor}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="CornerRadius" Value="0" />
        <Setter Property="Padding" Value="6" />
        <Setter Property="Template">
            <ControlTemplate>
                <Border Background="{TemplateBinding Background}" Name="root">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="20" />
                            <ColumnDefinition Width="5" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition SharedSizeGroup="MenuItemIGT" Width="Auto" />
                            <ColumnDefinition Width="20" />
                        </Grid.ColumnDefinitions>
                        <ContentControl
                            Content="{TemplateBinding Icon}"
                            Foreground="{TemplateBinding Foreground}"
                            Height="16"
                            HorizontalAlignment="Center"
                            Margin="5,0,0,0"
                            Name="icon"
                            VerticalAlignment="Center"
                            Width="16" />
                        <ContentControl
                            Grid.Column="0"
                            Height="16"
                            IsVisible="True"
                            Margin="5,0,0,0"
                            VerticalAlignment="Center"
                            Width="16"
                            x:Name="PART_ToggleIconPresenter" />
                        <ContentPresenter
                            Content="{TemplateBinding Header}"
                            ContentTemplate="{TemplateBinding HeaderTemplate}"
                            Foreground="{TemplateBinding Foreground}"
                            Grid.Column="2"
                            HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                            Margin="{TemplateBinding Padding}"
                            Name="PART_HeaderPresenter"
                            VerticalAlignment="Center">
                            <ContentPresenter.DataTemplates>
                                <DataTemplate DataType="sys:String">
                                    <AccessText Text="{Binding}" />
                                </DataTemplate>
                            </ContentPresenter.DataTemplates>
                        </ContentPresenter>
                        <Path
                            Data="F1M0.002,31.062L0,0 27.01,15.534z"
                            Fill="{DynamicResource MainTextColor}"
                            Grid.Column="4"
                            Height="8"
                            Margin="6,0,4,0"
                            Name="rightArrow"
                            Stretch="Fill"
                            VerticalAlignment="Center"
                            Width="8" />
                        <Popup
                            Grid.Column="0"
                            IsLightDismissEnabled="False"
                            IsOpen="{TemplateBinding IsSubMenuOpen,
                                                     Mode=TwoWay}"
                            Name="PART_Popup"
                            Placement="RightEdgeAlignedTop">
                            <Border
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="{TemplateBinding CornerRadius}">
                                <ItemsPresenter
                                    Grid.IsSharedSizeScope="True"
                                    ItemsPanel="{TemplateBinding ItemsPanel}"
                                    Margin="2"
                                    Name="PART_ItemsPresenter" />
                            </Border>
                        </Popup>
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter>

        <Style Selector="^:toggle /template/ Viewbox#PART_ToggleIconPresenter, ^:radio /template/ Viewbox#PART_ToggleIconPresenter">
            <Setter Property="IsVisible" Value="True" />
        </Style>
        <Style Selector="^:toggle /template/ ContentPresenter#PART_IconPresenter, ^:radio /template/ ContentPresenter#PART_IconPresenter">
            <Setter Property="IsVisible" Value="False" />
        </Style>
        <Style Selector="^:checked:toggle /template/ ContentControl#PART_ToggleIconPresenter">
            <Setter Property="Content">
                <Template>
                    <Path
                        Data="F1M10,1.2L4.7,9.1 4.5,9.1 0,5.2 1.3,3.5 4.3,6.1 8.3,0 10,1.2z"
                        Fill="{DynamicResource MainTextColor}"
                        VerticalAlignment="Center" />
                </Template>
            </Setter>
        </Style>
        <Style Selector="^:checked:radio /template/ ContentControl#PART_ToggleIconPresenter">
            <Setter Property="Content">
                <Template>
                    <Ellipse
                        Fill="{DynamicResource MainTextColor}"
                        Height="8"
                        Margin="4"
                        Width="8" />
                </Template>
            </Setter>
        </Style>

        <Style Selector="^:not(.noHover):selected /template/ Border#root">
            <Setter Property="Background" Value="{DynamicResource AccentColor}" />
            <Setter Property="BorderBrush" Value="{DynamicResource AccentColor}" />
        </Style>

        <Style Selector="^:not(.noHover):selected /template/ ContentPresenter#PART_HeaderPresenter">
            <Setter Property="Foreground" Value="{StaticResource SecondaryTextColor}" />
            <Setter Property="Effect" Value="{StaticResource TextShadow}" />
        </Style>

        <Style Selector="^:not(.noHover):selected /template/ ContentPresenter#icon">
            <Setter Property="Foreground" Value="{StaticResource SecondaryTextColor}" />
        </Style>

        <Style Selector="^:empty /template/ Path#rightArrow">
            <Setter Property="IsVisible" Value="False" />
        </Style>

        <Style Selector="^:disabled">
            <Setter Property="Opacity" Value="{StaticResource ThemeDisabledOpacity}" />
        </Style>

        <Style Selector="^.active /template/ Border#root">
            <Setter Property="Background" Value="{DynamicResource SecondaryAccentColor}" />
            <Setter Property="BorderBrush" Value="{DynamicResource SecondaryAccentColor}" />
        </Style>

        <Style Selector="^.active /template/ ContentPresenter#PART_HeaderPresenter">
            <Setter Property="Foreground" Value="{StaticResource SecondaryTextColor}" />
            <Setter Property="Effect" Value="{StaticResource TextShadow}" />
        </Style>

        <Style Selector="^.active /template/ ContentPresenter#icon">
            <Setter Property="Foreground" Value="{StaticResource SecondaryTextColor}" />
        </Style>

    </ControlTheme>
</ResourceDictionary>