<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ui="http://schemas.modernwpf.com/2019"
    xmlns:local="clr-namespace:ModernWpf.Controls">

    <Style TargetType="local:AppBarButton">
        <Setter Property="Background" Value="{DynamicResource AppBarButtonBackground}" />
        <Setter Property="Foreground" Value="{DynamicResource AppBarButtonForeground}" />
        <Setter Property="BorderBrush" Value="{DynamicResource AppBarButtonBorderBrush}" />
        <Setter Property="HorizontalAlignment" Value="Left" />
        <Setter Property="VerticalAlignment" Value="Top" />
        <Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" />
        <Setter Property="FontWeight" Value="Normal" />
        <Setter Property="Width" Value="68" />
        <Setter Property="UseSystemFocusVisuals" Value="{DynamicResource UseSystemFocusVisuals}" />
        <Setter Property="FocusVisualMargin" Value="-3" />
        <Setter Property="FocusVisualStyle" Value="{DynamicResource {x:Static SystemParameters.FocusVisualStyleKey}}" />
        <Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:AppBarButton">
                    <ControlTemplate.Resources>
                        <StreamGeometry x:Key="ChevronRight">M 5.029297 19.091797 L 14.111328 10 L 5.029297 0.908203 L 5.908203 0.029297 L 15.888672 10 L 5.908203 19.970703 Z</StreamGeometry>
                    </ControlTemplate.Resources>
                    <Border
                        x:Name="Root"
                        Background="Transparent"
                        MinWidth="{TemplateBinding MinWidth}"
                        MaxWidth="{TemplateBinding MaxWidth}"
                        SnapsToDevicePixels="True">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="ApplicationViewStates">
                                <ui:VisualStateGroupListener.Listener>
                                    <ui:VisualStateGroupListener x:Name="ApplicationViewStatesListener" />
                                </ui:VisualStateGroupListener.Listener>
                                <VisualState x:Name="FullSize" />
                                <VisualState x:Name="Compact" />
                                <VisualState x:Name="LabelOnRight" />
                                <VisualState x:Name="LabelCollapsed" />
                                <VisualState x:Name="Overflow" />
                                <VisualState x:Name="OverflowWithToggleButtons" />
                                <VisualState x:Name="OverflowWithMenuIcons" />
                                <VisualState x:Name="OverflowWithToggleButtonsAndMenuIcons" />
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="CommonStates">
                                <ui:VisualStateGroupListener.Listener>
                                    <ui:VisualStateGroupListener x:Name="CommonStatesListener" />
                                </ui:VisualStateGroupListener.Listener>
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="PointerOver" />
                                <VisualState x:Name="Pressed" />
                                <VisualState x:Name="Disabled" />
                                <VisualState x:Name="OverflowNormal" />
                                <VisualState x:Name="OverflowPointerOver" />
                                <VisualState x:Name="OverflowPressed" />
                                <!--<VisualState x:Name="OverflowSubMenuOpened" />-->
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="KeyboardAcceleratorTextVisibility">
                                <ui:VisualStateGroupListener.Listener>
                                    <ui:VisualStateGroupListener x:Name="KeyboardAcceleratorTextVisibilityListener" />
                                </ui:VisualStateGroupListener.Listener>
                                <VisualState x:Name="KeyboardAcceleratorTextCollapsed" />
                                <VisualState x:Name="KeyboardAcceleratorTextVisible" />
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FlyoutStates">
                                <ui:VisualStateGroupListener.Listener>
                                    <ui:VisualStateGroupListener x:Name="FlyoutStatesListener" />
                                </ui:VisualStateGroupListener.Listener>
                                <VisualState x:Name="NoFlyout" />
                                <VisualState x:Name="HasFlyout" />
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid>
                            <Border x:Name="AppBarButtonInnerBorder"                                       
                                    Margin="{DynamicResource AppBarButtonInnerBorderMargin}"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="{TemplateBinding CornerRadius}"
                                    ui:FocusVisualHelper.IsTemplateFocusTarget="True" />
                            
                            <Grid
                                x:Name="ContentRoot"
                                MinHeight="{DynamicResource AppBarThemeMinHeight}">

                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Viewbox
                                    x:Name="ContentViewbox"
                                    Height="{DynamicResource AppBarButtonContentHeight}"
                                    Margin="{DynamicResource AppBarButtonContentViewboxCollapsedMargin}"
                                    HorizontalAlignment="Stretch">
                                    <ContentPresenter
                                        x:Name="Content"
                                        Content="{TemplateBinding Icon}"
                                        TextElement.Foreground="{TemplateBinding Foreground}" />
                                </Viewbox>
                                <TextBlock
                                    x:Name="TextLabel"
                                    Grid.Row="1"
                                    Text="{TemplateBinding Label}"
                                    Foreground="{TemplateBinding Foreground}"
                                    FontSize="12"
                                    FontFamily="{TemplateBinding FontFamily}"
                                    TextAlignment="Center"
                                    TextWrapping="Wrap"
                                    Margin="{DynamicResource AppBarButtonTextLabelMargin}" />
                                <TextBlock
                                    x:Name="OverflowTextLabel"
                                    Text="{TemplateBinding Label}"
                                    Foreground="{TemplateBinding Foreground}"
                                    FontSize="{DynamicResource ControlContentThemeFontSize}"
                                    FontFamily="{TemplateBinding FontFamily}"
                                    TextAlignment="Left"
                                    TextWrapping="NoWrap"
                                    HorizontalAlignment="Stretch"
                                    VerticalAlignment="Center"
                                    Margin="12,0,12,0"
                                    Padding="{DynamicResource AppBarButtonOverflowTextLabelPadding}"
                                    Visibility="Collapsed" />
                                <TextBlock
                                    x:Name="KeyboardAcceleratorTextLabel"
                                    Grid.Column="1"
                                    Style="{DynamicResource CaptionTextBlockStyle}"
                                    Text="{TemplateBinding InputGestureText}"
                                    MinWidth="34"
                                    Margin="24,0,12,0"
                                    Foreground="{DynamicResource AppBarButtonKeyboardAcceleratorTextForeground}"
                                    HorizontalAlignment="Right"
                                    VerticalAlignment="Center"
                                    Visibility="Collapsed" />
                                <ui:FontIconFallback
                                    x:Name="SubItemChevron"
                                    Grid.Column="2"
                                    Data="{StaticResource ChevronRight}"
                                    FontFamily="{DynamicResource SymbolThemeFontFamily}"
                                    FontSize="12"
                                    Foreground="{DynamicResource MenuFlyoutSubItemChevron}"
                                    Margin="12,0,12,0"
                                    Visibility="Collapsed" />

                            </Grid>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <!--#region ApplicationViewStates-->
                        <!-- Compact -->
                        <Trigger SourceName="ApplicationViewStatesListener" Property="CurrentStateName" Value="Compact">
                            <Setter TargetName="AppBarButtonInnerBorder" Property="Margin" Value="{StaticResource AppBarButtonInnerBorderCompactMargin}" />
                            <Setter TargetName="TextLabel" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <!-- LabelOnRight -->
                        <Trigger SourceName="ApplicationViewStatesListener" Property="CurrentStateName" Value="LabelOnRight">
                            <Setter TargetName="ContentViewbox" Property="Margin" Value="{DynamicResource AppBarButtonContentViewboxMargin}" />
                            <Setter TargetName="ContentRoot" Property="MinHeight" Value="{DynamicResource AppBarThemeCompactHeight}" />
                            <Setter TargetName="TextLabel" Property="Grid.Row" Value="0" />
                            <Setter TargetName="TextLabel" Property="Grid.Column" Value="1" />
                            <Setter TargetName="TextLabel" Property="TextAlignment" Value="Left" />
                            <Setter TargetName="TextLabel" Property="Margin" Value="{DynamicResource AppBarButtonTextLabelOnRightMargin}" />
                            <Setter Property="Width" Value="NaN" />
                        </Trigger>
                        <!-- LabelCollapsed -->
                        <Trigger SourceName="ApplicationViewStatesListener" Property="CurrentStateName" Value="LabelCollapsed">
                            <Setter TargetName="ContentRoot" Property="MinHeight" Value="{DynamicResource AppBarThemeCompactHeight}" />
                            <Setter TargetName="TextLabel" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <!-- Overflow -->
                        <Trigger SourceName="ApplicationViewStatesListener" Property="CurrentStateName" Value="Overflow">
                            <Setter TargetName="ContentRoot" Property="MinHeight" Value="0" />
                            <Setter TargetName="AppBarButtonInnerBorder" Property="Margin" Value="{DynamicResource AppBarButtonInnerBorderOverflowMargin}" />
                            <Setter TargetName="ContentViewbox" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="TextLabel" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="OverflowTextLabel" Property="Visibility" Value="Visible" />
                        </Trigger>
                        <!-- OverflowWithToggleButtons -->
                        <Trigger SourceName="ApplicationViewStatesListener" Property="CurrentStateName" Value="OverflowWithToggleButtons">
                            <Setter TargetName="ContentRoot" Property="MinHeight" Value="0" />
                            <Setter TargetName="AppBarButtonInnerBorder" Property="Margin" Value="{DynamicResource AppBarButtonInnerBorderOverflowMargin}" />
                            <Setter TargetName="ContentViewbox" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="TextLabel" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="OverflowTextLabel" Property="Visibility" Value="Visible" />
                            <Setter TargetName="OverflowTextLabel" Property="Margin" Value="38,0,12,0" />
                        </Trigger>
                        <!-- OverflowWithMenuIcons -->
                        <Trigger SourceName="ApplicationViewStatesListener" Property="CurrentStateName" Value="OverflowWithMenuIcons">
                            <Setter TargetName="ContentRoot" Property="MinHeight" Value="0" />
                            <Setter TargetName="AppBarButtonInnerBorder" Property="Margin" Value="{DynamicResource AppBarButtonInnerBorderOverflowMargin}" />
                            <Setter TargetName="ContentViewbox" Property="HorizontalAlignment" Value="Left" />
                            <Setter TargetName="ContentViewbox" Property="VerticalAlignment" Value="Center" />
                            <Setter TargetName="ContentViewbox" Property="Width" Value="16" />
                            <Setter TargetName="ContentViewbox" Property="Height" Value="16" />
                            <Setter TargetName="ContentViewbox" Property="Margin" Value="12,0,12,0" />
                            <Setter TargetName="TextLabel" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="OverflowTextLabel" Property="Visibility" Value="Visible" />
                            <Setter TargetName="OverflowTextLabel" Property="Margin" Value="38,0,12,0" />
                        </Trigger>
                        <!-- OverflowWithToggleButtonsAndMenuIcons -->
                        <Trigger SourceName="ApplicationViewStatesListener" Property="CurrentStateName" Value="OverflowWithToggleButtonsAndMenuIcons">
                            <Setter TargetName="ContentRoot" Property="MinHeight" Value="0" />
                            <Setter TargetName="AppBarButtonInnerBorder" Property="Margin" Value="{DynamicResource AppBarButtonInnerBorderOverflowMargin}" />
                            <Setter TargetName="ContentViewbox" Property="HorizontalAlignment" Value="Left" />
                            <Setter TargetName="ContentViewbox" Property="VerticalAlignment" Value="Center" />
                            <Setter TargetName="ContentViewbox" Property="Width" Value="16" />
                            <Setter TargetName="ContentViewbox" Property="Height" Value="16" />
                            <Setter TargetName="ContentViewbox" Property="Margin" Value="38,0,12,0" />
                            <Setter TargetName="TextLabel" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="OverflowTextLabel" Property="Visibility" Value="Visible" />
                            <Setter TargetName="OverflowTextLabel" Property="Margin" Value="76,0,12,0" />
                        </Trigger>
                        <!--#endregion-->
                        <!--#region CommonStates-->
                        <!-- PointerOver -->
                        <Trigger SourceName="CommonStatesListener" Property="CurrentStateName" Value="PointerOver">
                            <Setter TargetName="AppBarButtonInnerBorder" Property="Background" Value="{DynamicResource AppBarButtonBackgroundPointerOver}" />
                            <Setter TargetName="AppBarButtonInnerBorder" Property="BorderBrush" Value="{DynamicResource AppBarButtonBorderBrushPointerOver}" />
                            <Setter TargetName="Content" Property="TextElement.Foreground" Value="{DynamicResource AppBarButtonForegroundPointerOver}" />
                            <Setter TargetName="TextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonForegroundPointerOver}" />
                            <Setter TargetName="OverflowTextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonForegroundPointerOver}" />
                            <Setter TargetName="KeyboardAcceleratorTextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonKeyboardAcceleratorTextForegroundPointerOver}" />
                        </Trigger>
                        <!-- Pressed -->
                        <Trigger SourceName="CommonStatesListener" Property="CurrentStateName" Value="Pressed">
                            <Setter TargetName="AppBarButtonInnerBorder" Property="Background" Value="{DynamicResource AppBarButtonBackgroundPressed}" />
                            <Setter TargetName="AppBarButtonInnerBorder" Property="BorderBrush" Value="{DynamicResource AppBarButtonBorderBrushPressed}" />
                            <Setter TargetName="Content" Property="TextElement.Foreground" Value="{DynamicResource AppBarButtonForegroundPressed}" />
                            <Setter TargetName="TextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonForegroundPressed}" />
                            <Setter TargetName="OverflowTextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonForegroundPressed}" />
                            <Setter TargetName="KeyboardAcceleratorTextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonKeyboardAcceleratorTextForegroundPressed}" />
                        </Trigger>
                        <!-- Disabled -->
                        <Trigger SourceName="CommonStatesListener" Property="CurrentStateName" Value="Disabled">
                            <Setter TargetName="AppBarButtonInnerBorder" Property="Background" Value="{DynamicResource AppBarButtonBackgroundDisabled}" />
                            <Setter TargetName="AppBarButtonInnerBorder" Property="BorderBrush" Value="{DynamicResource AppBarButtonBorderBrushDisabled}" />
                            <Setter TargetName="Content" Property="TextElement.Foreground" Value="{DynamicResource AppBarButtonForegroundDisabled}" />
                            <Setter TargetName="TextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonForegroundDisabled}" />
                            <Setter TargetName="OverflowTextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonForegroundDisabled}" />
                            <Setter TargetName="KeyboardAcceleratorTextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonKeyboardAcceleratorTextForegroundDisabled}" />
                        </Trigger>
                        <!-- OverflowPointerOver -->
                        <Trigger SourceName="CommonStatesListener" Property="CurrentStateName" Value="OverflowPointerOver">
                            <Setter TargetName="AppBarButtonInnerBorder" Property="Background" Value="{DynamicResource AppBarButtonBackgroundPointerOver}" />
                            <Setter TargetName="AppBarButtonInnerBorder" Property="BorderBrush" Value="{DynamicResource AppBarButtonBorderBrushPointerOver}" />
                            <Setter TargetName="Content" Property="TextElement.Foreground" Value="{DynamicResource AppBarButtonForegroundPointerOver}" />
                            <Setter TargetName="TextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonForegroundPointerOver}" />
                            <Setter TargetName="OverflowTextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonForegroundPointerOver}" />
                            <Setter TargetName="KeyboardAcceleratorTextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonKeyboardAcceleratorTextForegroundPointerOver}" />
                            <Setter TargetName="SubItemChevron" Property="Foreground" Value="{DynamicResource AppBarButtonSubItemChevronForegroundPointerOver}" />
                        </Trigger>
                        <!-- OverflowPressed -->
                        <Trigger SourceName="CommonStatesListener" Property="CurrentStateName" Value="OverflowPressed">
                            <Setter TargetName="AppBarButtonInnerBorder" Property="Background" Value="{DynamicResource AppBarButtonBackgroundPressed}" />
                            <Setter TargetName="AppBarButtonInnerBorder" Property="BorderBrush" Value="{DynamicResource AppBarButtonBorderBrushPressed}" />
                            <Setter TargetName="Content" Property="TextElement.Foreground" Value="{DynamicResource AppBarButtonForegroundPressed}" />
                            <Setter TargetName="TextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonForegroundPressed}" />
                            <Setter TargetName="OverflowTextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonForegroundPressed}" />
                            <Setter TargetName="KeyboardAcceleratorTextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonKeyboardAcceleratorTextForegroundPressed}" />
                            <Setter TargetName="SubItemChevron" Property="Foreground" Value="{DynamicResource AppBarButtonSubItemChevronForegroundPressed}" />
                        </Trigger>
                        <!-- OverflowSubMenuOpened -->
                        <!--<Trigger>
                            <Setter TargetName="AppBarButtonInnerBorder" Property="Background" Value="{DynamicResource AppBarButtonBackgroundSubMenuOpened}" />
                            <Setter TargetName="AppBarButtonInnerBorder" Property="BorderBrush" Value="{DynamicResource AppBarButtonBorderBrushSubMenuOpened}" />
                            <Setter TargetName="Content" Property="TextElement.Foreground" Value="{DynamicResource AppBarButtonForegroundSubMenuOpened}" />
                            <Setter TargetName="TextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonForegroundSubMenuOpened}" />
                            <Setter TargetName="OverflowTextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonForegroundSubMenuOpened}" />
                            <Setter TargetName="KeyboardAcceleratorTextLabel" Property="Foreground" Value="{DynamicResource AppBarButtonKeyboardAcceleratorTextForegroundSubMenuOpened}" />
                            <Setter TargetName="SubItemChevron" Property="Foreground" Value="{DynamicResource AppBarButtonSubItemChevronForegroundSubMenuOpened}" />
                        </Trigger>-->
                        <!--#endregion-->
                        <!-- KeyboardAcceleratorTextVisible -->
                        <Trigger SourceName="KeyboardAcceleratorTextVisibilityListener" Property="CurrentStateName" Value="KeyboardAcceleratorTextVisible">
                            <Setter TargetName="KeyboardAcceleratorTextLabel" Property="Visibility" Value="Visible" />
                        </Trigger>
                        <!-- HasFlyout -->
                        <Trigger SourceName="FlyoutStatesListener" Property="CurrentStateName" Value="HasFlyout">
                            <Setter TargetName="SubItemChevron" Property="Visibility" Value="Visible" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="ToolBar.IsOverflowItem" Value="True">
                <Setter Property="HorizontalAlignment" Value="Stretch" />
                <Setter Property="Width" Value="NaN" />
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>