<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals"
    xmlns:local="using:Microsoft.PowerToys.Settings.UI.Controls">

    <x:Double x:Key="TitleBarCompactHeight">32</x:Double>
    <x:Double x:Key="TitleBarTallHeight">48</x:Double>
    <x:Double x:Key="TitleBarContentMinWidth">360</x:Double>
    <Style BasedOn="{StaticResource DefaultTitleBarStyle}" TargetType="local:TitleBar" />

    <Style x:Key="DefaultTitleBarStyle" TargetType="local:TitleBar">
        <Setter Property="MinHeight" Value="{ThemeResource TitleBarCompactHeight}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:TitleBar">
                    <Grid
                        x:Name="PART_RootGrid"
                        Height="{TemplateBinding MinHeight}"
                        Padding="4,0,0,0"
                        VerticalAlignment="Stretch"
                        Background="{TemplateBinding Background}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition x:Name="PART_LeftPaddingColumn" Width="0" />
                            <ColumnDefinition x:Name="PART_ButtonsHolderColumn" Width="Auto" />
                            <ColumnDefinition x:Name="PART_IconColumn" Width="Auto" />
                            <ColumnDefinition x:Name="PART_TitleColumn" Width="Auto" />
                            <ColumnDefinition
                                x:Name="PART_LeftDragColumn"
                                Width="*"
                                MinWidth="4" />
                            <ColumnDefinition x:Name="PART_ContentColumn" Width="Auto" />
                            <ColumnDefinition
                                x:Name="PART_RightDragColumn"
                                Width="*"
                                MinWidth="4" />
                            <ColumnDefinition x:Name="PART_FooterColumn" Width="Auto" />
                            <ColumnDefinition x:Name="PART_RightPaddingColumn" Width="0" />
                        </Grid.ColumnDefinitions>
                        <Border
                            x:Name="PART_IconHolder"
                            Grid.Column="2"
                            Margin="12,0,0,0"
                            VerticalAlignment="Center">
                            <Viewbox
                                x:Name="PART_Icon"
                                MaxWidth="16"
                                MaxHeight="16">
                                <ContentPresenter
                                    x:Name="PART_IconPresenter"
                                    AutomationProperties.AccessibilityView="Raw"
                                    Content="{TemplateBinding Icon}"
                                    HighContrastAdjustment="None" />
                            </Viewbox>
                        </Border>

                        <StackPanel
                            x:Name="PART_TitleHolder"
                            Grid.Column="3"
                            Margin="16,0,0,0"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            Orientation="Horizontal"
                            Spacing="4">
                            <TextBlock
                                x:Name="PART_TitleText"
                                MinWidth="48"
                                Margin="0,0,0,1"
                                Foreground="{ThemeResource TextFillColorPrimaryBrush}"
                                Style="{StaticResource CaptionTextBlockStyle}"
                                Text="{TemplateBinding Title}"
                                TextTrimming="CharacterEllipsis"
                                TextWrapping="NoWrap" />
                            <TextBlock
                                x:Name="PART_SubtitleText"
                                MinWidth="48"
                                Margin="0,0,0,1"
                                Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                Style="{StaticResource CaptionTextBlockStyle}"
                                Text="{TemplateBinding Subtitle}"
                                TextTrimming="CharacterEllipsis"
                                TextWrapping="NoWrap" />
                        </StackPanel>
                        <Grid
                            x:Name="PART_DragRegion"
                            Grid.Column="2"
                            Grid.ColumnSpan="6"
                            Background="Transparent" />
                        <StackPanel
                            x:Name="PART_ButtonHolder"
                            Grid.Column="1"
                            Orientation="Horizontal">
                            <Button
                                x:Name="PART_BackButton"
                                Style="{ThemeResource TitleBarBackButtonStyle}"
                                ToolTipService.ToolTip="Back" />
                            <Button
                                x:Name="PART_PaneButton"
                                Style="{StaticResource TitleBarPaneToggleButtonStyle}"
                                ToolTipService.ToolTip="Toggle menu" />
                        </StackPanel>

                        <ContentPresenter
                            x:Name="PART_ContentPresenter"
                            Grid.Column="5"
                            MinWidth="{ThemeResource TitleBarContentMinWidth}"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Center"
                            HorizontalContentAlignment="Stretch"
                            Content="{TemplateBinding Content}" />
                        <ContentPresenter
                            x:Name="PART_FooterPresenter"
                            Grid.Column="7"
                            Margin="4,0,8,0"
                            HorizontalContentAlignment="Right"
                            Content="{TemplateBinding Footer}" />
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="BackButtonStates">
                                <VisualState x:Name="BackButtonVisible" />
                                <VisualState x:Name="BackButtonCollapsed">
                                    <VisualState.Setters>
                                        <Setter Target="PART_BackButton.Visibility" Value="Collapsed" />
                                        <Setter Target="PART_BackButton.Visibility" Value="Collapsed" />
                                    </VisualState.Setters>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="PaneButtonStates">
                                <VisualState x:Name="PaneButtonVisible" />
                                <VisualState x:Name="PaneButtonCollapsed">
                                    <VisualState.Setters>
                                        <Setter Target="PART_PaneButton.Visibility" Value="Collapsed" />
                                    </VisualState.Setters>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="IconStates">
                                <VisualState x:Name="IconVisible" />
                                <VisualState x:Name="IconCollapsed">
                                    <VisualState.Setters>
                                        <Setter Target="PART_IconHolder.Visibility" Value="Collapsed" />
                                        <Setter Target="PART_TitleHolder.Margin" Value="4,0,0,0" />
                                    </VisualState.Setters>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="ContentStates">
                                <VisualState x:Name="ContentVisible" />
                                <VisualState x:Name="ContentCollapsed">
                                    <VisualState.Setters>
                                        <Setter Target="PART_ContentPresenter.Visibility" Value="Collapsed" />
                                    </VisualState.Setters>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FooterStates">
                                <VisualState x:Name="FooterVisible" />
                                <VisualState x:Name="FooterCollapsed">
                                    <VisualState.Setters>
                                        <Setter Target="PART_FooterPresenter.Visibility" Value="Collapsed" />
                                    </VisualState.Setters>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="ReflowStates">
                                <VisualState x:Name="Wide" />
                                <VisualState x:Name="Narrow">
                                    <VisualState.Setters>
                                        <Setter Target="PART_TitleHolder.Visibility" Value="Collapsed" />
                                        <Setter Target="PART_LeftDragColumn.Width" Value="Auto" />
                                        <Setter Target="PART_RightDragColumn.Width" Value="Auto" />
                                        <Setter Target="PART_RightDragColumn.MinWidth" Value="16" />
                                        <Setter Target="PART_LeftDragColumn.MinWidth" Value="16" />
                                        <Setter Target="PART_ContentColumn.Width" Value="*" />
                                        <!--  Content can stretch now  -->
                                        <Setter Target="PART_ContentPresenter.MinWidth" Value="0" />
                                    </VisualState.Setters>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="WindowActivationStates">
                                <VisualState x:Name="Activated" />
                                <VisualState x:Name="Deactivated">
                                    <VisualState.Setters>
                                        <Setter Target="PART_TitleText.Foreground" Value="{ThemeResource TextFillColorDisabledBrush}" />
                                        <Setter Target="PART_SubtitleText.Foreground" Value="{ThemeResource TextFillColorDisabledBrush}" />
                                        <Setter Target="PART_BackButton.IsEnabled" Value="False" />
                                        <Setter Target="PART_PaneButton.IsEnabled" Value="False" />
                                    </VisualState.Setters>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="DisplayModeStates">
                                <VisualState x:Name="Standard" />
                                <VisualState x:Name="Tall">
                                    <VisualState.Setters>
                                        <Setter Target="PART_RootGrid.MinHeight" Value="{ThemeResource TitleBarTallHeight}" />
                                        <Setter Target="PART_RootGrid.Padding" Value="4" />
                                    </VisualState.Setters>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--  Copy of WinUI NavigationBackButtonNormalStyle - cannot use it as it picks up the generic.xaml version, not the WinUI version  -->
    <Style x:Key="TitleBarBackButtonStyle" TargetType="Button">
        <Setter Property="Background" Value="{ThemeResource NavigationViewBackButtonBackground}" />
        <Setter Property="Foreground" Value="{ThemeResource NavigationViewItemForegroundChecked}" />
        <Setter Property="FontFamily" Value="{ThemeResource SymbolThemeFontFamily}" />
        <Setter Property="FontSize" Value="16" />
        <Setter Property="MaxHeight" Value="40" />
        <Setter Property="VerticalAlignment" Value="Stretch" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
        <Setter Property="Content" Value="&#xE72B;" />
        <Setter Property="Padding" Value="12,4,12,4" />
        <Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid
                        x:Name="RootGrid"
                        Padding="{TemplateBinding Padding}"
                        Background="{TemplateBinding Background}"
                        CornerRadius="{TemplateBinding CornerRadius}">
                        <AnimatedIcon
                            x:Name="Content"
                            Width="16"
                            Height="16"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            AnimatedIcon.State="Normal"
                            AutomationProperties.AccessibilityView="Raw">
                            <animatedvisuals:AnimatedBackVisualSource />
                            <AnimatedIcon.FallbackIconSource>
                                <FontIconSource
                                    FontFamily="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=FontFamily}"
                                    FontSize="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=FontSize}"
                                    Glyph="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}"
                                    MirroredWhenRightToLeft="True" />
                            </AnimatedIcon.FallbackIconSource>
                        </AnimatedIcon>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="PointerOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" Storyboard.TargetProperty="Background">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource NavigationViewButtonBackgroundPointerOver}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource NavigationViewButtonForegroundPointerOver}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                    <VisualState.Setters>
                                        <Setter Target="Content.(AnimatedIcon.State)" Value="PointerOver" />
                                    </VisualState.Setters>
                                </VisualState>

                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" Storyboard.TargetProperty="Background">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource NavigationViewButtonBackgroundPressed}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource NavigationViewButtonForegroundPressed}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                    <VisualState.Setters>
                                        <Setter Target="Content.(AnimatedIcon.State)" Value="Pressed" />
                                    </VisualState.Setters>
                                </VisualState>

                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource NavigationViewButtonForegroundDisabled}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--  Copy of WinUI PaneToggleButtonStyle - cannot use it as it picks up the generic.xaml version, not the WinUI version  -->
    <Style x:Key="TitleBarPaneToggleButtonStyle" TargetType="Button">
        <Setter Property="Background" Value="{ThemeResource NavigationViewBackButtonBackground}" />
        <Setter Property="Foreground" Value="{ThemeResource NavigationViewItemForegroundChecked}" />
        <Setter Property="FontFamily" Value="{ThemeResource SymbolThemeFontFamily}" />
        <Setter Property="FontSize" Value="16" />
        <Setter Property="MaxHeight" Value="40" />
        <Setter Property="VerticalAlignment" Value="Stretch" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
        <Setter Property="Content" Value="&#xE700;" />
        <Setter Property="Padding" Value="12,4,12,4" />
        <Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid
                        x:Name="RootGrid"
                        Padding="{TemplateBinding Padding}"
                        Background="{TemplateBinding Background}"
                        CornerRadius="{TemplateBinding CornerRadius}">
                        <AnimatedIcon
                            x:Name="Content"
                            Width="16"
                            Height="16"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            AnimatedIcon.State="Normal"
                            AutomationProperties.AccessibilityView="Raw">
                            <animatedvisuals:AnimatedGlobalNavigationButtonVisualSource />
                            <AnimatedIcon.FallbackIconSource>
                                <FontIconSource
                                    FontFamily="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=FontFamily}"
                                    FontSize="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=FontSize}"
                                    Glyph="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}"
                                    MirroredWhenRightToLeft="True" />
                            </AnimatedIcon.FallbackIconSource>
                        </AnimatedIcon>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="PointerOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" Storyboard.TargetProperty="Background">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource NavigationViewButtonBackgroundPointerOver}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource NavigationViewButtonForegroundPointerOver}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                    <VisualState.Setters>
                                        <Setter Target="Content.(AnimatedIcon.State)" Value="PointerOver" />
                                    </VisualState.Setters>
                                </VisualState>

                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" Storyboard.TargetProperty="Background">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource NavigationViewButtonBackgroundPressed}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource NavigationViewButtonForegroundPressed}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                    <VisualState.Setters>
                                        <Setter Target="Content.(AnimatedIcon.State)" Value="Pressed" />
                                    </VisualState.Setters>
                                </VisualState>

                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource NavigationViewButtonForegroundDisabled}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
