<n:BaseScreenRecorder x:Class="ScreenToGif.Windows.NewRecorder"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:n="clr-namespace:ScreenToGif.Controls"
                      xmlns:c="clr-namespace:ScreenToGif.Util.Converters"
                      xmlns:u="clr-namespace:ScreenToGif.Util"
                      xmlns:t="clr-namespace:ScreenToGif.Settings"
                      x:Name="RecorderWindow" Title="ScreenToGif" SnapsToDevicePixels="True" UseLayoutRounding="True" AllowsTransparency="False"
                      WindowStyle="None" Topmost="True" Icon="../Resources/Logo.ico" SizeToContent="WidthAndHeight" ResizeMode="CanMinimize" MinWidth="220"
                      FocusManager.FocusedElement="{Binding RelativeSource={x:Static RelativeSource.Self}, Mode=OneTime}" WindowStartupLocation="Manual"
                      Loaded="Window_Loaded" Activated="Window_Activated" KeyDown="Window_KeyDown" StateChanged="Window_StateChanged" Closing="Window_Closing">

    <n:BaseRecorder.TaskbarItemInfo>
        <TaskbarItemInfo>
            <TaskbarItemInfo.ThumbButtonInfos>
                <ThumbButtonInfoCollection>
                    <ThumbButtonInfo x:Name="RecordThumbInfo" Command="{Binding RecordCommand}" DismissWhenClicked="True" 
                                     Description="{DynamicResource S.Recorder.Record}" CommandTarget="{Binding ElementName=RecordButton}"
                                     Visibility="{Binding ElementName=RecordButton, Path=Visibility, Mode=OneWay}">
                        <ThumbButtonInfo.ImageSource>
                            <DrawingImage Drawing="{Binding Source={StaticResource Vector.Record}, Path=Drawing, Mode=OneTime}"/>
                        </ThumbButtonInfo.ImageSource>
                    </ThumbButtonInfo>

                    <ThumbButtonInfo x:Name="SnapThumbInfo" Command="{Binding SnapCommand}" DismissWhenClicked="True" 
                                     Description="{DynamicResource S.Recorder.Snap}" CommandTarget="{Binding ElementName=SnapButton}"
                                     Visibility="{Binding ElementName=SnapButton, Path=Visibility, Mode=OneWay}">
                        <ThumbButtonInfo.ImageSource>
                            <DrawingImage Drawing="{Binding Source={StaticResource Vector.Camera.Add}, Path=Drawing, Mode=OneTime}"/>
                        </ThumbButtonInfo.ImageSource>
                    </ThumbButtonInfo>

                    <ThumbButtonInfo x:Name="PauseThumbInfo" Command="{Binding PauseCommand}" DismissWhenClicked="True" 
                                     Description="{DynamicResource S.Recorder.Pause}" CommandTarget="{Binding ElementName=PauseButton}"
                                     Visibility="{Binding ElementName=PauseButton, Path=Visibility, Mode=OneWay}">
                        <ThumbButtonInfo.ImageSource>
                            <DrawingImage Drawing="{Binding Source={StaticResource Vector.Pause}, Path=Drawing, Mode=OneTime}"/>
                        </ThumbButtonInfo.ImageSource>
                    </ThumbButtonInfo>

                    <ThumbButtonInfo x:Name="StopLargeThumbInfo" Command="{Binding StopLargeCommand}" DismissWhenClicked="True" 
                                     Description="{DynamicResource S.Recorder.Stop}" CommandTarget="{Binding ElementName=StopLargeButton}"
                                     Visibility="{Binding ElementName=StopLargeButton, Path=Visibility, Mode=OneWay}">
                        <ThumbButtonInfo.ImageSource>
                            <DrawingImage Drawing="{Binding Source={StaticResource Vector.Stop}, Path=Drawing, Mode=OneTime}"/>
                        </ThumbButtonInfo.ImageSource>
                    </ThumbButtonInfo>

                    <ThumbButtonInfo x:Name="StopThumbInfo" Command="{Binding StopCommand}" DismissWhenClicked="True" 
                                     Description="{DynamicResource S.Recorder.Stop}" CommandTarget="{Binding ElementName=StopSmallButton}"
                                     Visibility="{Binding ElementName=StopSmallButton, Path=Visibility, Mode=OneWay}">
                        <ThumbButtonInfo.ImageSource>
                            <DrawingImage Drawing="{Binding Source={StaticResource Vector.Stop}, Path=Drawing, Mode=OneTime}"/>
                        </ThumbButtonInfo.ImageSource>
                    </ThumbButtonInfo>

                    <ThumbButtonInfo Visibility="Hidden"/>

                    <ThumbButtonInfo x:Name="DiscardThumbInfo" Command="{Binding DiscardCommand}" DismissWhenClicked="True" 
                                     Description="{DynamicResource S.Recorder.Discard}" CommandTarget="{Binding ElementName=DiscardButton}">
                        <ThumbButtonInfo.ImageSource>
                            <DrawingImage Drawing="{Binding Source={StaticResource Vector.Remove}, Path=Drawing, Mode=OneTime}"/>
                        </ThumbButtonInfo.ImageSource>
                    </ThumbButtonInfo>
                </ThumbButtonInfoCollection>
            </TaskbarItemInfo.ThumbButtonInfos>
        </TaskbarItemInfo>
    </n:BaseRecorder.TaskbarItemInfo>
    
    <Border Background="{DynamicResource Panel.Background}" BorderThickness="1" BorderBrush="{DynamicResource Element.Border.Weak}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="30"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <Grid.Resources>
                <c:CommandToKeyGesture x:Key="CommandToKeyGesture"/>
                <c:KeyGestureToString x:Key="KeyGestureToString"/>
                <c:BoolOrToVisibility x:Key="BoolOrToVisibility"/>
                <c:BoolAndToVisibility x:Key="BoolAndToVisibility"/>
                <c:BoolOr x:Key="BoolOr"/>
                <c:IntToBool x:Key="IntToBool"/>
            </Grid.Resources>

            <Grid Grid.Row="0" x:Name="HeaderGrid" Background="{DynamicResource Panel.Background}" MouseLeftButtonDown="HeaderGrid_MouseLeftButtonDown">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="30"/>
                    <ColumnDefinition Width="30"/>
                </Grid.ColumnDefinitions>

                <TextBlock Grid.Column="0" Text="{Binding ElementName=RecorderWindow, Path=Title, FallbackValue=ScreenToGif}" Margin="5,0,3,0"
                           VerticalAlignment="Center" FontSize="16" Foreground="{DynamicResource Element.Foreground.Header}"/>

                <!--<TextBlock Grid.Column="1" VerticalAlignment="Center" Margin="5">
                    <Run Text="{Binding ElementName=RecorderWindow, Path=Left, StringFormat={}{0}}"/>
                    <Run Text="x"/>
                    <Run Text="{Binding ElementName=RecorderWindow, Path=Top, StringFormat={}{0}}"/>
                </TextBlock>-->
                
                <TextBlock Grid.Column="1" Text="{DynamicResource S.Recorder.ClickOrPress}" VerticalAlignment="Center" TextAlignment="Center" Margin="5" 
                           Foreground="{DynamicResource Element.Foreground.Gray112}">
                    <TextBlock.Visibility>
                        <MultiBinding Converter="{StaticResource BoolAndToVisibility}">
                            <Binding Source="{x:Static t:UserSettings.All}" Path="CaptureFrequency" Converter="{StaticResource EnumToBool}" ConverterParameter="{x:Static u:CaptureFrequency.Interaction}"/>
                            <Binding ElementName="RecorderWindow" Path="FrameCount" Converter="{StaticResource IntToBool}" ConverterParameter="0"/>
                        </MultiBinding>
                    </TextBlock.Visibility>
                </TextBlock>

                <n:DisplayTimer Grid.Column="2" x:Name="DisplayTimer" Margin="5" CornerRadius="3" Padding="5,0" CapturedCount="{Binding ElementName=RecorderWindow, Path=FrameCount}"
                                IsImpreciseCapture="{Binding ElementName=RecorderWindow, Path=HasImpreciseCapture}"/>

                <Grid Grid.Column="3" Background="{StaticResource Vector.Cursor}" Margin="3,5" ToolTip="{DynamicResource S.Recorder.CursorFollowing}" Width="16"
                      Visibility="{Binding ElementName=RecorderWindow, Path=IsFollowing, Converter={StaticResource Bool2Visibility}}"/>

                <n:ExtendedButton Grid.Column="4" x:Name="MinimizeButton" Style="{StaticResource Style.Button.NoText}" Icon="{DynamicResource Vector.Minimize}" 
                                  Width="30" Padding="6" TabIndex="9" ContentHeight="14" ContentWidth="14" UseLayoutRounding="True" Click="MinimizeButton_Click"/>
                <n:ExtendedButton Grid.Column="5" x:Name="CloseButton" Style="{StaticResource Style.Button.NoText}" Icon="{DynamicResource Vector.Close}" 
                                  Width="30" Padding="6" TabIndex="10" ContentHeight="14" ContentWidth="14" UseLayoutRounding="True" Command="{Binding CloseCommand}"/>
            </Grid>

            
            <Grid Grid.Row="1" x:Name="RecordControlsGrid" MinWidth="250" Height="64" 
                  Visibility="{Binding Source={x:Static t:UserSettings.All}, Path=RecorderCompactMode, Converter={StaticResource InvertedBoolToVisibility}, FallbackValue={x:Static Visibility.Visible}}">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

                <!--Options-->
                <n:ExtendedButton Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" ContentHeight="24" ContentWidth="24" TabIndex="0" MinWidth="65" 
                                  Text="{DynamicResource S.StartUp.Options}" Icon="{StaticResource Vector.Options}" Style="{StaticResource Style.Button.Vertical}" 
                                  Command="{Binding OptionsCommand}" KeyGesture="{Binding OptionsCommand, Converter={StaticResource CommandToKeyGesture}}"/>

                <Separator Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" Width="1" Margin="3,2"/>

                <!--Framerate-->
                <Grid Grid.Row="0" Grid.Column="2" Grid.RowSpan="2" MinWidth="100">
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>

                    <Grid Grid.Row="0" x:Name="FrequencyGrid">
                        <Grid.Visibility>
                            <MultiBinding Converter="{StaticResource BoolOrToVisibility}">
                                <Binding Source="{x:Static t:UserSettings.All}" Path="CaptureFrequency" Converter="{StaticResource EnumToBool}" ConverterParameter="{x:Static u:CaptureFrequency.PerHour}"/>
                                <Binding Source="{x:Static t:UserSettings.All}" Path="CaptureFrequency" Converter="{StaticResource EnumToBool}" ConverterParameter="{x:Static u:CaptureFrequency.PerMinute}"/>
                                <Binding Source="{x:Static t:UserSettings.All}" Path="CaptureFrequency" Converter="{StaticResource EnumToBool}" ConverterParameter="{x:Static u:CaptureFrequency.PerSecond}"/>
                            </MultiBinding>
                        </Grid.Visibility>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>

                        <Viewbox Grid.Row="0" Grid.Column="0" x:Name="FrequencyViewbox" Stretch="Uniform" ClipToBounds="True" Focusable="False" Opacity="{DynamicResource Element.Opacity}"
                                 ToolTipService.HorizontalOffset="-5" ToolTipService.Placement="Bottom" ToolTip="{DynamicResource S.Recorder.Fps.Range}">

                            <Grid HorizontalAlignment="Center" VerticalAlignment="Center" FlowDirection="LeftToRight" Margin="-4">
                                <n:CircularProgressBar StrokeThickness="2" Percentage="100" SegmentColor="Gray" Radius="24" IsTabStop="False"/>
                                <n:CircularProgressBar StrokeThickness="22" Percentage="100" SegmentColor="#FFF0F1F1" Radius="10" IsTabStop="False"/>

                                <n:CircularProgressBar StrokeThickness="2" Value="{Binding ElementName=FrequencyIntegerUpDown, Path=Value, Mode=OneWay}" 
                                                       IsInverted="True" Minimum="1" Maximum="60" SegmentColor="#FFE28A73" Radius="24" IsTabStop="False"/>
                                <n:CircularProgressBar StrokeThickness="22" Value="{Binding ElementName=FrequencyIntegerUpDown, Path=Value, Mode=OneWay}" 
                                                       IsInverted="True" Minimum="1" Maximum="60" SegmentColor="#FFE28A73" Radius="10" IsTabStop="False"/>
                            </Grid>
                        </Viewbox>

                        <n:IntegerUpDown Grid.Row="0" Grid.Column="1" x:Name="FrequencyIntegerUpDown" Margin="1,3" MinWidth="45" TabIndex="1"
                                         StepValue="1" Minimum="1" Maximum="60" Value="{Binding Source={x:Static t:UserSettings.All}, Path=LatestFps, Mode=TwoWay}" 
                                         ToolTipService.HorizontalOffset="-5" ToolTipService.Placement="Bottom" ToolTip="{DynamicResource S.Recorder.Fps}"/>

                        <TextBlock Grid.Row="0" Grid.Column="2" x:Name="FrequencyTextBlock" Text="{DynamicResource S.Recorder.Fps.Short}" FontSize="12" Margin="1,0,0,0" VerticalAlignment="Center" 
                                   Padding="0" Foreground="{DynamicResource Element.Foreground}" ToolTip="{Binding ElementName=FrequencyIntegerUpDown, Path=ToolTip}"/>
                    </Grid>

                    <TextBlock Grid.Row="0" Text="…" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="{DynamicResource Element.Foreground.Gray112}">
                        <TextBlock.Visibility>
                            <MultiBinding Converter="{StaticResource BoolOrToVisibility}">
                                <Binding Source="{x:Static t:UserSettings.All}" Path="CaptureFrequency" Converter="{StaticResource EnumToBool}" ConverterParameter="{x:Static u:CaptureFrequency.Manual}"/>
                                <Binding Source="{x:Static t:UserSettings.All}" Path="CaptureFrequency" Converter="{StaticResource EnumToBool}" ConverterParameter="{x:Static u:CaptureFrequency.Interaction}"/>
                            </MultiBinding>
                        </TextBlock.Visibility>
                    </TextBlock>

                    <n:SplitButton Grid.Row="1" Grid.Column="0" ContentHeight="20" Padding="3" TabIndex="2"
                                   Style="{StaticResource Style.SplitButton.NoBorder}" IsEnabled="{Binding ElementName=FrequencyIntegerUpDown, Path=IsEnabled, Mode=OneWay}"
                                   SelectedIndex="{Binding Source={x:Static t:UserSettings.All}, Path=CaptureFrequency, Converter={StaticResource EnumToInt}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                   ToolTip="{DynamicResource S.Recorder.SwitchFrequency}" ToolTipService.Placement="Bottom" ToolTipService.HorizontalOffset="-5"
                                   Command="{Binding SwitchFrequencyCommand}" CommandParameter="Switch">
                        
                        <n:ExtendedMenuItem Header="{DynamicResource S.Options.Recorder.Frequency}" IsHitTestVisible="False" Icon="{StaticResource Vector.Record}" ContentHeight="16" ContentWidth="16" Tag="I"/>

                        <Separator Height="1" Margin="3,2"/>

                        <n:ExtendedMenuItem Header="{DynamicResource S.Options.Recorder.Frequency.Manual}" Tag="S.Options.Recorder.Frequency.Manual" IsCheckable="True" Icon="{StaticResource Vector.Camera}" ContentHeight="16" ContentWidth="16" 
                                         IsChecked="{Binding CaptureFrequency, Source={x:Static t:UserSettings.All}, Converter={StaticResource EnumToBool}, ConverterParameter={x:Static u:CaptureFrequency.Manual}, UpdateSourceTrigger=PropertyChanged}" 
                                         IsEnabled="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked, Converter={StaticResource InvertedBool}, UpdateSourceTrigger=PropertyChanged}" 
                                         Command="{Binding SwitchFrequencyCommand}" CommandParameter="{x:Static u:CaptureFrequency.Manual}"/>

                        <n:ExtendedMenuItem Header="{DynamicResource S.Options.Recorder.Frequency.Interaction}" Tag="S.Options.Recorder.Frequency.Interaction" IsCheckable="True" Icon="{StaticResource Vector.Cursor}" ContentHeight="16" ContentWidth="16" 
                                         IsChecked="{Binding CaptureFrequency, Source={x:Static t:UserSettings.All}, Converter={StaticResource EnumToBool}, ConverterParameter={x:Static u:CaptureFrequency.Interaction}, UpdateSourceTrigger=PropertyChanged}" 
                                         IsEnabled="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked, Converter={StaticResource InvertedBool}, UpdateSourceTrigger=PropertyChanged}" 
                                         Command="{Binding SwitchFrequencyCommand}" CommandParameter="{x:Static u:CaptureFrequency.Interaction}"/>
                        
                        <n:ExtendedMenuItem Header="{DynamicResource S.Options.Recorder.Frequency.Second}" Tag="S.Options.Recorder.Frequency.Second" IsCheckable="True" Icon="{StaticResource Vector.Delay}" ContentHeight="16" ContentWidth="16" 
                                         IsChecked="{Binding CaptureFrequency, Source={x:Static t:UserSettings.All}, Converter={StaticResource EnumToBool}, ConverterParameter={x:Static u:CaptureFrequency.PerSecond}, UpdateSourceTrigger=PropertyChanged}" 
                                         IsEnabled="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked, Converter={StaticResource InvertedBool}, UpdateSourceTrigger=PropertyChanged}" 
                                         Command="{Binding SwitchFrequencyCommand}" CommandParameter="{x:Static u:CaptureFrequency.PerSecond}"/>

                        <n:ExtendedMenuItem Header="{DynamicResource S.Options.Recorder.Frequency.Minute}" Tag="S.Options.Recorder.Frequency.Minute" IsCheckable="True" Icon="{StaticResource Vector.Delay.Minute}" ContentHeight="16" ContentWidth="16" 
                                         IsChecked="{Binding CaptureFrequency, Source={x:Static t:UserSettings.All}, Converter={StaticResource EnumToBool}, ConverterParameter={x:Static u:CaptureFrequency.PerMinute}, UpdateSourceTrigger=PropertyChanged}" 
                                         IsEnabled="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked, Converter={StaticResource InvertedBool}, UpdateSourceTrigger=PropertyChanged}" 
                                         Command="{Binding SwitchFrequencyCommand}" CommandParameter="{x:Static u:CaptureFrequency.PerMinute}"/>

                        <n:ExtendedMenuItem Header="{DynamicResource S.Options.Recorder.Frequency.Hour}" Tag="S.Options.Recorder.Frequency.Hour" IsCheckable="True" Icon="{StaticResource Vector.Delay.Hour}" ContentHeight="16" ContentWidth="16" 
                                         IsChecked="{Binding CaptureFrequency, Source={x:Static t:UserSettings.All}, Converter={StaticResource EnumToBool}, ConverterParameter={x:Static u:CaptureFrequency.PerHour}, UpdateSourceTrigger=PropertyChanged}" 
                                         IsEnabled="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked, Converter={StaticResource InvertedBool}, UpdateSourceTrigger=PropertyChanged}" 
                                         Command="{Binding SwitchFrequencyCommand}" CommandParameter="{x:Static u:CaptureFrequency.PerHour}"/>
                    </n:SplitButton>
                </Grid>

                <Separator Grid.Row="0" Grid.Column="3" Grid.RowSpan="2" Width="1" Margin="3,2"/>

                <!--Region Selection-->
                <Grid Grid.Row="0" Grid.Column="4" Grid.RowSpan="2" x:Name="RegionGrid" MinWidth="110">
                    <Grid.IsEnabled>
                        <MultiBinding Converter="{StaticResource BoolOr}" ConverterParameter="0">
                            <Binding ElementName="StopLargeButton" Path="IsEnabled"/>
                            <Binding ElementName="StopSmallButton" Path="IsEnabled"/>
                            <Binding ElementName="PauseButton" Path="IsEnabled"/>
                        </MultiBinding>
                    </Grid.IsEnabled>
                    
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>

                    <!--Area/Window/Screen-->
                    <Grid x:Name="SizeGrid" Visibility="Collapsed">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>

                        <n:IntegerBox Grid.Column="0" x:Name="WidthIntegerBox" Value="{Binding RegionWidth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalContentAlignment="Center"
                                      Offset="2" Minimum="25" Maximum="4096" TabIndex="3" Height="Auto" Padding="4,0" Margin="1,3"
                                      ToolTip="{DynamicResource S.Recorder.Width}" ToolTipService.Placement="Bottom" ToolTipService.HorizontalOffset="-5"
                                      PropagateWheelEvent="True" ValueChanged="SizeIntegerBox_ValueChanged" MouseWheel="SizeIntegerBox_MouseWheel"/>

                        <TextBlock Grid.Column="1" Text="×" FontSize="16" FontFamily="Segoe Script" Margin="1" VerticalAlignment="Center" Padding="0" Foreground="{DynamicResource Element.Foreground}"/>

                        <n:IntegerBox Grid.Column="2" x:Name="HeightIntegerBox" Value="{Binding RegionHeight, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalContentAlignment="Center"
                                      Offset="2" Minimum="25" Maximum="4096" TabIndex="4" Height="Auto" Padding="4,0" Margin="1,3"
                                      ToolTip="{DynamicResource S.Recorder.Height}" ToolTipService.Placement="Bottom" ToolTipService.HorizontalOffset="-5"
                                      PropagateWheelEvent="True" ValueChanged="SizeIntegerBox_ValueChanged" MouseWheel="SizeIntegerBox_MouseWheel"/>

                        <TextBlock Grid.Column="3" Text="px" FontSize="12" Margin="1,0,0,0" VerticalAlignment="Center" Padding="0" Foreground="{DynamicResource Element.Foreground}"/>
                    </Grid>

                    <TextBlock Grid.Row="0" x:Name="SizeTextBlock" Text="..." TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center" 
                               Foreground="{DynamicResource Element.Foreground.Gray112}"/>

                    <n:SplitButton Grid.Row="1" ContentHeight="20" Padding="3" TabIndex="5" Style="{StaticResource Style.SplitButton.NoBorder}"
                                   SelectedIndex="{Binding Source={x:Static t:UserSettings.All}, Path=RecorderModeIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                   Foreground="{Binding Source={x:Static t:UserSettings.All}, Path=RecorderForeground, Mode=TwoWay, Converter={StaticResource ColorToBrush}}">
                        <n:ExtendedMenuItem Icon="{StaticResource Vector.Crop}" Header="{DynamicResource S.Recorder.Area.Select}" Tag="S.Recorder.Area" ContentHeight="16" ContentWidth="16" Click="RegionButton_Click"/>
                        <n:ExtendedMenuItem Icon="{StaticResource Vector.Application}" Header="{DynamicResource S.Recorder.Window.Select}" Tag="S.Recorder.Window" ContentHeight="16" ContentWidth="16" Click="WindowButton_Click"/>
                        <n:ExtendedMenuItem Icon="{StaticResource Vector.Monitor}" Header="{DynamicResource S.Recorder.Screen.Select}" Tag="S.Recorder.Screen" ContentHeight="16" ContentWidth="16" Click="FullScreenButton_Click"/>
                    </n:SplitButton>
                </Grid>

                <Separator Grid.Row="0" Grid.Column="5" Grid.RowSpan="2" Width="1" Margin="3,2"/>

                <!--Snap-->
                <n:ExtendedButton Grid.Row="0" Grid.Column="6" Grid.RowSpan="2" x:Name="SnapButton" ContentHeight="24" ContentWidth="24" TabIndex="6" MinWidth="65" 
                                  Text="{DynamicResource S.Recorder.Snap}" Icon="{StaticResource Vector.Camera.Add}" Style="{StaticResource Style.Button.Vertical}" 
                                  Command="{Binding SnapCommand}" KeyGesture="{Binding RecordKeyGesture, Converter={StaticResource KeyGestureToString}, UpdateSourceTrigger=PropertyChanged}"
                                  Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, Converter={StaticResource Bool2Visibility}}"/>

                <!--Record-->
                <n:ExtendedButton Grid.Row="0" Grid.Column="6" Grid.RowSpan="2" x:Name="RecordButton" ContentHeight="24" ContentWidth="24" TabIndex="6" MinWidth="65"
                                  Text="{DynamicResource S.Recorder.Record}" Icon="{StaticResource Vector.Record}" Style="{StaticResource Style.Button.Vertical}" 
                                  Command="{Binding RecordCommand}" KeyGesture="{Binding RecordKeyGesture, Converter={StaticResource KeyGestureToString}, UpdateSourceTrigger=PropertyChanged}"
                                  Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, Converter={StaticResource Bool2Visibility}}"/>

                <!--Pause-->
                <n:ExtendedButton Grid.Row="0" Grid.Column="6" Grid.RowSpan="2" x:Name="PauseButton" ContentHeight="24" ContentWidth="24" TabIndex="6" MinWidth="65"
                                  Text="{DynamicResource S.Recorder.Pause}" Icon="{StaticResource Vector.Pause}" Style="{StaticResource Style.Button.Vertical}" 
                                  Command="{Binding PauseCommand}" KeyGesture="{Binding RecordKeyGesture, Converter={StaticResource KeyGestureToString}, UpdateSourceTrigger=PropertyChanged}"
                                  Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, Converter={StaticResource Bool2Visibility}}"/>

                <!--Discard-->
                <n:ExtendedButton Grid.Row="0" Grid.Column="7" x:Name="DiscardButton" ContentHeight="16" ContentWidth="16" TabIndex="7" MinWidth="65"
                                  Text="{DynamicResource S.Recorder.Discard}" Icon="{StaticResource Vector.Remove}" Style="{StaticResource Style.Button.Horizontal}" 
                                  Command="{Binding DiscardCommand}" KeyGesture="{Binding DiscardKeyGesture, Converter={StaticResource KeyGestureToString}, UpdateSourceTrigger=PropertyChanged}"
                                  Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, Converter={StaticResource Bool2Visibility}, FallbackValue={x:Static Visibility.Collapsed}}"/>

                <!--Stop (when recording)-->
                <n:ExtendedButton Grid.Row="0" Grid.Column="7" Grid.RowSpan="2" x:Name="StopLargeButton" ContentHeight="24" ContentWidth="24" TabIndex="8" MinWidth="65"
                                  Text="{DynamicResource S.Recorder.Stop}" Icon="{StaticResource Vector.Stop}" Style="{StaticResource Style.Button.Vertical}" 
                                  Command="{Binding StopLargeCommand}" KeyGesture="{Binding StopKeyGesture, Converter={StaticResource KeyGestureToString}, UpdateSourceTrigger=PropertyChanged}"
                                  Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, Converter={StaticResource Bool2Visibility}, FallbackValue={x:Static Visibility.Collapsed}}"/>

                <!--Stop (when paused/manual capture)-->
                <n:ExtendedButton Grid.Row="1" Grid.Column="7" x:Name="StopSmallButton" ContentHeight="16" ContentWidth="16" TabIndex="8" MinWidth="65"
                                  Text="{DynamicResource S.Recorder.Stop}" Icon="{StaticResource Vector.Stop}" Style="{StaticResource Style.Button.Horizontal}" 
                                  Command="{Binding StopCommand}" KeyGesture="{Binding StopKeyGesture, Converter={StaticResource KeyGestureToString}, UpdateSourceTrigger=PropertyChanged}"
                                  Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, Converter={StaticResource Bool2Visibility}, FallbackValue={x:Static Visibility.Collapsed}}"/>
            </Grid>

            <Grid Grid.Row="1" Height="32" MinWidth="100" IsEnabled="{Binding ElementName=RecordControlsGrid, Path=IsEnabled, Mode=OneWay}"
                  Visibility="{Binding Source={x:Static t:UserSettings.All}, Path=RecorderCompactMode, Converter={StaticResource Bool2Visibility}, FallbackValue={x:Static Visibility.Collapsed}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto" MaxWidth="26"/>
                    <ColumnDefinition Width="Auto" MaxWidth="32"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto" MaxWidth="50"/>
                    <ColumnDefinition Width="Auto" MaxWidth="26"/>
                    <ColumnDefinition Width="Auto" MaxWidth="26"/>
                    <ColumnDefinition Width="Auto" MaxWidth="26"/>
                </Grid.ColumnDefinitions>

                <n:ExtendedButton Grid.Column="1" x:Name="OptionsButton" Icon="{DynamicResource Vector.Options}" Margin="0" Padding="3" 
                                  Style="{DynamicResource Style.Button.NoText}" ContentHeight="22" ContentWidth="22" Command="{Binding OptionsCommand}" TabIndex="0"
                                  ToolTipService.HorizontalOffset="-5" ToolTipService.Placement="Bottom" ToolTip="{DynamicResource S.StartUp.Options}"/>

                <Viewbox Grid.Column="2" Stretch="UniformToFill" ClipToBounds="True" Focusable="False" Opacity="{DynamicResource Element.Opacity}"
                         ToolTip="{Binding ElementName=FrequencyViewbox, Path=ToolTip, Mode=OneWay}" ToolTipService.HorizontalOffset="-5" ToolTipService.Placement="Bottom"
                         Visibility="{Binding ElementName=FrequencyGrid, Path=Visibility, Mode=OneWay, FallbackValue={x:Static Visibility.Visible}}">

                    <Grid HorizontalAlignment="Center" VerticalAlignment="Center" FlowDirection="LeftToRight" Margin="-4">
                        <n:CircularProgressBar StrokeThickness="2" Percentage="100" SegmentColor="Gray" Radius="24" IsTabStop="False"/>
                        <n:CircularProgressBar StrokeThickness="22" Percentage="100" SegmentColor="#FFF0F1F1" Radius="10" IsTabStop="False"/>

                        <n:CircularProgressBar StrokeThickness="2" Value="{Binding ElementName=FrequencyIntegerUpDown, Path=Value, Mode=OneWay}" 
                                               IsInverted="True" Minimum="1" Maximum="60" SegmentColor="#FFE28A73" Radius="24" IsTabStop="False"/>
                        <n:CircularProgressBar StrokeThickness="22" Value="{Binding ElementName=FrequencyIntegerUpDown, Path=Value, Mode=OneWay}" 
                                               IsInverted="True" Minimum="1" Maximum="60" SegmentColor="#FFE28A73" Radius="10" IsTabStop="False"/>
                    </Grid>
                </Viewbox>

                <n:IntegerUpDown Grid.Column="3" Margin="1,3" StepValue="1" Minimum="1" Maximum="60" MinWidth="45" TabIndex="1"
                                 Value="{Binding Source={x:Static t:UserSettings.All}, Path=LatestFps, Mode=TwoWay}" IsEnabled="{Binding ElementName=FrequencyIntegerUpDown, Path=IsEnabled, Mode=OneWay}"
                                 ToolTip="{Binding ElementName=FrequencyIntegerUpDown, Path=ToolTip, Mode=OneWay}" ToolTipService.HorizontalOffset="-5" ToolTipService.Placement="Bottom"
                                 Visibility="{Binding ElementName=FrequencyGrid, Path=Visibility, Mode=OneWay}"/>

                <n:ExtendedButton Grid.Column="4" Style="{StaticResource Style.Button.Horizontal.NoImage}" Margin="1,0,0,0" VerticalContentAlignment="Center" Padding="0"
                                  UseLayoutRounding="True" TabIndex="3" Text="{Binding ElementName=FrequencyTextBlock, Path=Text, Mode=OneWay}" FontSize="12" TextWrapping="NoWrap"
                                  ToolTip="{DynamicResource S.Recorder.SwitchFrequency}" ToolTipService.Placement="Bottom" ToolTipService.HorizontalOffset="-5"
                                  Command="{Binding SwitchFrequencyCommand}" CommandParameter="Switch">
                    <n:ExtendedButton.ContextMenu>
                        <ContextMenu IsOpen="False">
                            <n:ExtendedMenuItem Header="{DynamicResource S.Options.Recorder.Frequency}" IsHitTestVisible="False" Icon="{StaticResource Vector.Record}" ContentHeight="16" ContentWidth="16"/>
                            <Separator/>

                            <n:ExtendedMenuItem Header="{DynamicResource S.Options.Recorder.Frequency.Manual}" IsCheckable="True" Icon="{StaticResource Vector.Camera}" ContentHeight="16" ContentWidth="16" 
                                                IsChecked="{Binding CaptureFrequency, Source={x:Static t:UserSettings.All}, Converter={StaticResource EnumToBool}, ConverterParameter={x:Static u:CaptureFrequency.Manual}}" 
                                                IsEnabled="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked, Converter={StaticResource InvertedBool}}" 
                                                Command="{Binding SwitchFrequencyCommand}" CommandParameter="{x:Static u:CaptureFrequency.Manual}"/>

                            <n:ExtendedMenuItem Header="{DynamicResource S.Options.Recorder.Frequency.Interaction}" IsCheckable="True" Icon="{StaticResource Vector.Cursor}" ContentHeight="16" ContentWidth="16" 
                                                IsChecked="{Binding CaptureFrequency, Source={x:Static t:UserSettings.All}, Converter={StaticResource EnumToBool}, ConverterParameter={x:Static u:CaptureFrequency.Interaction}}" 
                                                IsEnabled="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked, Converter={StaticResource InvertedBool}, UpdateSourceTrigger=PropertyChanged}" 
                                                Command="{Binding SwitchFrequencyCommand}" CommandParameter="{x:Static u:CaptureFrequency.Interaction}"/>
                            
                            <n:ExtendedMenuItem Header="{DynamicResource S.Options.Recorder.Frequency.Second}" IsCheckable="True" Icon="{StaticResource Vector.Delay}" ContentHeight="16" ContentWidth="16" 
                                                IsChecked="{Binding CaptureFrequency, Source={x:Static t:UserSettings.All}, Converter={StaticResource EnumToBool}, ConverterParameter={x:Static u:CaptureFrequency.PerSecond}}" 
                                                IsEnabled="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked, Converter={StaticResource InvertedBool}}" 
                                                Command="{Binding SwitchFrequencyCommand}" CommandParameter="{x:Static u:CaptureFrequency.PerSecond}"/>

                            <n:ExtendedMenuItem Header="{DynamicResource S.Options.Recorder.Frequency.Minute}" IsCheckable="True" Icon="{StaticResource Vector.Delay.Minute}" ContentHeight="16" ContentWidth="16" 
                                                IsChecked="{Binding CaptureFrequency, Source={x:Static t:UserSettings.All}, Converter={StaticResource EnumToBool}, ConverterParameter={x:Static u:CaptureFrequency.PerMinute}}" 
                                                IsEnabled="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked, Converter={StaticResource InvertedBool}}"
                                                Command="{Binding SwitchFrequencyCommand}" CommandParameter="{x:Static u:CaptureFrequency.PerMinute}"/>

                            <n:ExtendedMenuItem Header="{DynamicResource S.Options.Recorder.Frequency.Hour}" IsCheckable="True" Icon="{StaticResource Vector.Delay.Hour}" ContentHeight="16" ContentWidth="16" 
                                                IsChecked="{Binding CaptureFrequency, Source={x:Static t:UserSettings.All}, Converter={StaticResource EnumToBool}, ConverterParameter={x:Static u:CaptureFrequency.PerHour}}" 
                                                IsEnabled="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked, Converter={StaticResource InvertedBool}}" 
                                                Command="{Binding SwitchFrequencyCommand}" CommandParameter="{x:Static u:CaptureFrequency.PerHour}"/>
                        </ContextMenu>
                    </n:ExtendedButton.ContextMenu>
                </n:ExtendedButton>

                <Separator Grid.Column="5" Width="1" Margin="5,2" HorizontalAlignment="Left"/>

                <n:SplitButton Grid.Column="6" x:Name="ReselectSplitButton" Style="{StaticResource Style.SplitButton.NoBorder.NoText}" ContentHeight="20" Padding="3" TabIndex="4"
                               SelectedIndex="{Binding Source={x:Static t:UserSettings.All}, Path=RecorderModeIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                               Foreground="{Binding Source={x:Static t:UserSettings.All}, Path=RecorderForeground, Mode=TwoWay, Converter={StaticResource ColorToBrush}}"
                               Visibility="{Binding ElementName=RegionGrid, Path=IsEnabled, Converter={StaticResource Bool2Visibility}}">
                    <n:ExtendedMenuItem Icon="{StaticResource Vector.Crop}" Header="{DynamicResource S.Recorder.Area}" ContentHeight="16" ContentWidth="16" Click="RegionButton_Click"/>
                    <n:ExtendedMenuItem Icon="{StaticResource Vector.Application}" Header="{DynamicResource S.Recorder.Window}" ContentHeight="16" ContentWidth="16" Click="WindowButton_Click"/>
                    <n:ExtendedMenuItem Icon="{StaticResource Vector.Monitor}" Header="{DynamicResource S.Recorder.Screen}" ContentHeight="16" ContentWidth="16" Click="FullScreenButton_Click"/>
                </n:SplitButton>

                <!--Discard-->
                <n:ExtendedButton Grid.Column="7" Icon="{DynamicResource Vector.Remove}" ContentHeight="20" ContentWidth="20" Padding="3" TabIndex="5"
                                  Style="{StaticResource Style.Button.NoText}" Command="{Binding DiscardCommand}" KeyGesture="{Binding DiscardCommand, Converter={StaticResource CommandToKeyGesture}}" 
                                  ToolTip="{DynamicResource S.Recorder.Discard}" Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, Converter={StaticResource Bool2Visibility}}"/>

                <!--Snap-->
                <n:ExtendedButton Grid.Column="8" Icon="{StaticResource Vector.Camera.Add}" ContentHeight="20" ContentWidth="20" Padding="3" TabIndex="6"
                                  Style="{StaticResource Style.Button.NoText}" Command="{Binding SnapCommand}" KeyGesture="{Binding SnapCommand, Converter={StaticResource CommandToKeyGesture}}" 
                                  ToolTip="{DynamicResource S.Recorder.Snap}" Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, Converter={StaticResource Bool2Visibility}}"/>

                <!--Record-->
                <n:ExtendedButton Grid.Column="8" Icon="{StaticResource Vector.Record}" ContentHeight="20" ContentWidth="20" Padding="3" TabIndex="6" 
                                  Style="{StaticResource Style.Button.NoText}" Command="{Binding RecordCommand}" KeyGesture="{Binding RecordCommand, Converter={StaticResource CommandToKeyGesture}}" 
                                  ToolTip="{DynamicResource S.Recorder.Record}" Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, Converter={StaticResource Bool2Visibility}}"/>

                <!--Pause-->
                <n:ExtendedButton Grid.Column="8" Icon="{StaticResource Vector.Pause}" ContentHeight="20" ContentWidth="20" Padding="3" TabIndex="6" 
                                  Style="{StaticResource Style.Button.NoText}" Command="{Binding PauseCommand}" KeyGesture="{Binding PauseCommand, Converter={StaticResource CommandToKeyGesture}}" 
                                  ToolTip="{DynamicResource S.Recorder.Pause}" Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, Converter={StaticResource Bool2Visibility}}"/>

                <!--Stop-->
                <n:ExtendedButton Grid.Column="9" Icon="{DynamicResource Vector.Stop}" ContentHeight="20" ContentWidth="20" Padding="3" TabIndex="7"
                                  Style="{StaticResource Style.Button.NoText}" Command="{Binding StopCommand}" KeyGesture="{Binding StopCommand, Converter={StaticResource CommandToKeyGesture}}" 
                                  ToolTip="{DynamicResource S.Recorder.Stop}" Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, Converter={StaticResource Bool2Visibility}}"/>
            </Grid>
        </Grid>
    </Border>
</n:BaseScreenRecorder>