<UserControl x:Class="_1RM.View.Editor.Forms.RdpFormView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:controls="clr-namespace:_1RM.Controls"
             xmlns:controls1="clr-namespace:Shawn.Utils.Wpf.Controls;assembly=Shawn.Utils.Wpf"
             xmlns:forms="clr-namespace:_1RM.View.Editor.Forms"
             xmlns:protocol="clr-namespace:_1RM.Model.Protocol"
             xmlns:s="https://github.com/canton7/Stylet"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance forms:RdpFormViewModel}"
             d:DesignHeight="1850" d:DesignWidth="800">
    <StackPanel>

        <StackPanel>

            <TextBlock Style="{StaticResource EditorGroupTextBlockTitle}" Text="{DynamicResource 'Connection Info'}"></TextBlock>

            <Grid Style="{StaticResource EditorRowGrid}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource Hostname}"></TextBlock>
                    <Grid Style="{StaticResource EditorRowGridInput}">
                        <TextBox Text="{Binding New.Address, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, ValidatesOnNotifyDataErrors=True}"
                                 Tag="e.g. 192.168.0.101"></TextBox>
                    </Grid>
                    <TextBlock Style="{StaticResource EditorRowGridTitleFollowing}" Width="60" Text="{DynamicResource Port}"></TextBlock>
                    <Grid Style="{StaticResource EditorRowGridInput}">
                        <TextBox Text="{Binding New.Port, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, ValidatesOnNotifyDataErrors=True}"
                                 MinWidth="50" HorizontalAlignment="Left"
                                 InputMethod.IsInputMethodEnabled="False"
                                 InputScope="Number"></TextBox>
                    </Grid>
                </StackPanel>
            </Grid>


            <Grid Style="{StaticResource EditorRowGrid}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="Domain"></TextBlock>
                    <Grid Style="{StaticResource EditorRowGridInput}">
                        <TextBox Text="{Binding New.Domain, UpdateSourceTrigger=PropertyChanged}"></TextBox>
                    </Grid>
                </StackPanel>
            </Grid>


            <Grid Style="{StaticResource EditorRowGrid}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource User}"></TextBlock>
                    <Grid Style="{StaticResource EditorRowGridInput}">
                        <TextBox Text="{Binding New.UserName, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, ValidatesOnNotifyDataErrors=True}"></TextBox>
                    </Grid>
                </StackPanel>
            </Grid>


            <Grid Style="{StaticResource EditorRowGrid}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource Password}"></TextBlock>
                    <Grid Style="{StaticResource EditorRowGridInput}">
                        <controls:PasswordInput Height="28"
                                                Tag="leave it blank and it will prompt for the password later."
                                                Password="{Binding New.Password, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, ValidatesOnNotifyDataErrors=True}"/>
                    </Grid>
                    <CheckBox Margin="5 0 0 0" Content="{DynamicResource 'Ask for password when open connect'}" IsChecked="{Binding New.AskPasswordWhenConnect}"></CheckBox>
                </StackPanel>
            </Grid>


            <Grid Style="{StaticResource EditorRowGrid}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="LoadBalanceInfo"></TextBlock>
                    <Grid Style="{StaticResource EditorRowGridInput}">
                        <TextBox Text="{Binding New.LoadBalanceInfo, UpdateSourceTrigger=PropertyChanged}" Tag="tsv://MS Terminal Services Plugin.1.Wortell_sLab_Ses"></TextBox>
                    </Grid>
                </StackPanel>
            </Grid>

            <ContentControl s:View.Model="{Binding AlternativeCredentialListViewModel}"></ContentControl>
        </StackPanel>


        <StackPanel>
            <TextBlock Style="{StaticResource EditorGroupTextBlockTitle}" Text="{DynamicResource server_editor_group_title_display}"></TextBlock>
            <Grid>
                <Grid.Style>
                    <Style TargetType="Grid" BasedOn="{StaticResource EditorRowGrid}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding New.RdpFullScreenFlag}" Value="{x:Static protocol:ERdpFullScreenFlag.EnableFullScreen}">
                                <Setter Property="Margin" Value="0"></Setter>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding New.RdpFullScreenFlag}" Value="{x:Static protocol:ERdpFullScreenFlag.EnableFullAllScreens}">
                                <Setter Property="Margin" Value="0"></Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Grid.Style>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource server_editor_display_full_screen_flag}"></TextBlock>
                    <Grid Style="{StaticResource EditorRowGridInput}">
                        <Grid.Resources>
                            <forms:ConverterERdpFullScreenFlag x:Key="ConverterERdpFullScreenFlag" />
                        </Grid.Resources>
                        <ComboBox SelectedIndex="{Binding New.RdpFullScreenFlag, Converter={StaticResource ConverterERdpFullScreenFlag}}">
                            <ComboBoxItem Content="{DynamicResource server_editor_display_full_screen_flag_window}" />
                            <ComboBoxItem Content="{DynamicResource server_editor_display_full_screen_flag_full_screen}" />
                            <ComboBoxItem Content="{DynamicResource server_editor_display_full_screen_flag_all_screens}" />
                            <ComboBoxItem Visibility="{Binding New.RdpFullScreenFlag, Converter={StaticResource ConverterEqual2Visible}, ConverterParameter={x:Null}}" Content="{Binding New.ServerEditorDifferentOptions}" />
                        </ComboBox>
                    </Grid>

                    <TextBlock Style="{StaticResource TextBlockBase}" VerticalAlignment="Center" Margin="2 0" 
                               Visibility="{Binding New.RdpFullScreenFlag, Converter={StaticResource ConverterEqual2Collapsed}, ConverterParameter={x:Static protocol:ERdpFullScreenFlag.Disable}}"
                               ToolTip="{DynamicResource 'How to select the specified monitors'}">
                               <Hyperlink NavigateUri="https://1remote.github.io/usage/protocol/especial/rdp-in-mstsc-mode/#additional-settings" TextDecorations="{x:Null}" 
                                          controls1:HyperlinkHelper.IsOpenExternal="True">
                            (?)
                        </Hyperlink>
                    </TextBlock>
                </StackPanel>
            </Grid>
            <Grid Style="{StaticResource EditorRowGrid}" 
                  Visibility="{Binding New.RdpFullScreenFlag, Converter={StaticResource ConverterEqual2Collapsed}, ConverterParameter={x:Static protocol:ERdpFullScreenFlag.Disable}}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text=""></TextBlock>
                    <Grid>
                        <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                            <Grid Style="{StaticResource EditorRowGridInput}" Width="Auto">
                                <StackPanel>
                                    <CheckBox Content="{DynamicResource 'New session always use full screen'}" 
                                              IsChecked="{Binding New.IsConnWithFullScreen}">
                                        <CheckBox.Style>
                                            <Style TargetType="CheckBox" BasedOn="{StaticResource CheckBoxAccentStyle}">
                                                <Setter Property="Margin" Value="0 5 0 5"></Setter>
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding New.RdpFullScreenFlag}" Value="{x:Static protocol:ERdpFullScreenFlag.EnableFullAllScreens}">
                                                        <Setter Property="CheckBox.IsChecked" Value="True"></Setter>
                                                        <Setter Property="CheckBox.IsEnabled" Value="False"></Setter>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </CheckBox.Style>
                                    </CheckBox>
                                    <CheckBox Content="{DynamicResource 'New session use full screen if the last session is full screen'}" 
                                              IsChecked="{Binding New.IsConnWithFullScreen, Converter={StaticResource ConverterBoolInverse}}">
                                        <CheckBox.Style>
                                            <Style TargetType="CheckBox" BasedOn="{StaticResource CheckBoxAccentStyle}">
                                                <Setter Property="Margin" Value="0 0 0 5"></Setter>
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding New.RdpFullScreenFlag}" Value="{x:Static protocol:ERdpFullScreenFlag.EnableFullAllScreens}">
                                                        <Setter Property="CheckBox.IsChecked" Value="False"></Setter>
                                                        <Setter Property="CheckBox.IsEnabled" Value="False"></Setter>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </CheckBox.Style>
                                    </CheckBox>
                                    <CheckBox Content="{DynamicResource 'Display the connection bar when use the full screen'}" 
                                              Margin="0 0 0 5"
                                              IsChecked="{Binding New.IsFullScreenWithConnectionBar}"></CheckBox>
                                    <CheckBox Content="{DynamicResource 'Pin the connection bar by default'}" 
                                              IsChecked="{Binding New.IsPinTheConnectionBarByDefault}" 
                                              IsEnabled="{Binding New.IsFullScreenWithConnectionBar}"></CheckBox>
                                </StackPanel>
                            </Grid>
                        </StackPanel>
                    </Grid>
                </StackPanel>
            </Grid>

            <Grid Style="{StaticResource EditorRowGrid}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource Resolution}"></TextBlock>
                    <Grid Style="{StaticResource EditorRowGridInput}">
                        <Grid.Resources>
                            <forms:ConverterERdpWindowResizeMode x:Key="ConverterERdpWindowResizeMode" />
                        </Grid.Resources>
                        <ComboBox Name="ComboBoxResolution" SelectedIndex="{Binding New.RdpWindowResizeMode, Converter={StaticResource ConverterERdpWindowResizeMode}}">
                            <ComboBoxItem Content="{DynamicResource 'Fit to window'}"></ComboBoxItem>
                            <ComboBoxItem Content="{DynamicResource 'Custom resolution (stretch)'}"
                                          Visibility="{Binding New.RdpFullScreenFlag, Converter={StaticResource ConverterEqual2Collapsed}, ConverterParameter={x:Static protocol:ERdpFullScreenFlag.EnableFullAllScreens}}">
                            </ComboBoxItem>
                            <ComboBoxItem Content="{DynamicResource 'Custom resolution (fixed)'}" 
                                          Visibility="{Binding New.RdpFullScreenFlag, Converter={StaticResource ConverterEqual2Collapsed}, ConverterParameter={x:Static protocol:ERdpFullScreenFlag.EnableFullAllScreens}}">
                            </ComboBoxItem>
                            <ComboBoxItem Content="{DynamicResource 'Full-screen resolution (stretch)'}"
                                          Visibility="{Binding New.RdpFullScreenFlag, Converter={StaticResource ConverterEqual2Collapsed}, ConverterParameter={x:Static protocol:ERdpFullScreenFlag.Disable}}">
                            </ComboBoxItem>
                            <ComboBoxItem Content="{DynamicResource 'Full-screen resolution (fixed)'}"
                                          Visibility="{Binding New.RdpFullScreenFlag, Converter={StaticResource ConverterEqual2Collapsed}, ConverterParameter={x:Static protocol:ERdpFullScreenFlag.Disable}}">
                            </ComboBoxItem>
                            <ComboBoxItem Visibility="{Binding New.RdpWindowResizeMode, Converter={StaticResource ConverterEqual2Visible}, ConverterParameter={x:Null}}" 
                                          Content="{Binding New.ServerEditorDifferentOptions}" />
                        </ComboBox>
                    </Grid>

                    <StackPanel Orientation="Horizontal">
                        <StackPanel.Style>
                            <Style TargetType="StackPanel">
                                <Setter Property="Visibility" Value="Hidden"></Setter>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding New.RdpWindowResizeMode}" Value="{x:Static protocol:ERdpWindowResizeMode.Stretch}">
                                        <Setter Property="Visibility" Value="Visible"></Setter>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding New.RdpWindowResizeMode}" Value="{x:Static protocol:ERdpWindowResizeMode.Fixed}">
                                        <Setter Property="Visibility" Value="Visible"></Setter>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </StackPanel.Style>
                        <TextBlock Style="{StaticResource EditorRowGridTitle}" Width="80" Text="W = " Margin="20 0 0 0"></TextBlock>
                        <Grid Style="{StaticResource EditorRowGridInput}" Width="Auto">
                            <TextBox Text="{Binding New.RdpWidth, UpdateSourceTrigger=PropertyChanged}" Width="50" HorizontalAlignment="Left"></TextBox>
                        </Grid>
                        <TextBlock Style="{StaticResource EditorRowGridTitle}" Width="40" Text="H = " Margin="5 0 0 0"></TextBlock>
                        <Grid Style="{StaticResource EditorRowGridInput}" Width="Auto">
                            <TextBox Text="{Binding New.RdpHeight, UpdateSourceTrigger=PropertyChanged}" Width="50" HorizontalAlignment="Left"></TextBox>
                        </Grid>
                    </StackPanel>
                </StackPanel>
            </Grid>


            <Grid Style="{StaticResource EditorRowGrid}" 
                  Visibility="{Binding New.MstscModeEnabled, Converter={StaticResource ConverterBool2VisibleInv}}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource Scale}"></TextBlock>
                    <Grid Style="{StaticResource EditorRowGridInput}" Width="Auto">
                        <CheckBox HorizontalAlignment="Left" Margin="0 0 10 0" 
                                  Content="{DynamicResource 'Follow system'}" 
                                  IsChecked="{Binding New.IsScaleFactorFollowSystem}"></CheckBox>
                    </Grid>
                </StackPanel>
            </Grid>

            <Grid>
                <Grid.Style>
                    <Style TargetType="Grid" BasedOn="{StaticResource EditorRowGrid}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding New.MstscModeEnabled}" Value="True">
                                <Setter Property="Visibility" Value="Collapsed"></Setter>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding New.IsScaleFactorFollowSystem}" Value="True">
                                <Setter Property="Visibility" Value="Collapsed"></Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Grid.Style>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text=""></TextBlock>
                    <Grid Style="{StaticResource EditorRowGridInput}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" VerticalAlignment="Center" Margin="0 0 5 0" Text="{DynamicResource Custom}" Foreground="{DynamicResource BackgroundTextBrush}"></TextBlock>
                        <Slider Grid.Column="1" Value="{Binding New.ScaleFactorCustomValue, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" Minimum="100" Maximum="200"></Slider>
                        <TextBox Grid.Column="2" Width="50" TextAlignment="Center" Text="{Binding New.ScaleFactorCustomValue, UpdateSourceTrigger=PropertyChanged}"></TextBox>
                    </Grid>
                </StackPanel>
            </Grid>


            <Grid Style="{StaticResource EditorRowGrid}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource server_editor_display_rdp_performance}"></TextBlock>
                    <Grid Style="{StaticResource EditorRowGridInput}">
                        <Grid.Resources>
                            <forms:ConverterEDisplayPerformance x:Key="ConverterEDisplayPerformance" />
                        </Grid.Resources>
                        <ComboBox SelectedIndex="{Binding New.DisplayPerformance, Converter={StaticResource ConverterEDisplayPerformance}}">
                            <ComboBoxItem Content="{DynamicResource server_editor_display_rdp_performance_auto}" ToolTip="{DynamicResource server_editor_display_rdp_performance_auto}" />
                            <ComboBoxItem Content="{DynamicResource server_editor_display_rdp_performance_low}" ToolTip="{DynamicResource server_editor_display_rdp_performance_low}" />
                            <ComboBoxItem Content="{DynamicResource server_editor_display_rdp_performance_middle}" ToolTip="{DynamicResource server_editor_display_rdp_performance_middle}" />
                            <ComboBoxItem Content="{DynamicResource server_editor_display_rdp_performance_high}" ToolTip="{DynamicResource server_editor_display_rdp_performance_high}" />
                            <ComboBoxItem Visibility="{Binding New.DisplayPerformance, Converter={StaticResource ConverterEqual2Visible}, ConverterParameter={x:Null}}" Content="{Binding New.ServerEditorDifferentOptions}" />
                        </ComboBox>
                    </Grid>
                </StackPanel>
            </Grid>
        </StackPanel>


        <StackPanel>
            <TextBlock Style="{StaticResource EditorGroupTextBlockTitle}" Text="{DynamicResource 'mstsc.exe mode'}"></TextBlock>


            <Grid Style="{StaticResource EditorRowGrid}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" VerticalAlignment="Top" Text=""></TextBlock>
                    <StackPanel>
                        <CheckBox Margin="0 2"
                                  IsChecked="{Binding New.MstscModeEnabled}">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Style="{StaticResource TextBlockBase}" TextWrapping="Wrap" Margin="0 0 5 0">
                                    <Run Text="{DynamicResource Enabled}"></Run>
                                    <Hyperlink NavigateUri="https://1remote.github.io/usage/protocol/especial/rdp-in-mstsc-mode/" TextDecorations="{x:Null}" 
                                               controls1:HyperlinkHelper.IsOpenExternal="True">
                                        (?)
                                    </Hyperlink>
                                </TextBlock>
                            </StackPanel>
                        </CheckBox>
                        <TextBlock Width="500" TextWrapping="Wrap" Margin="0 5 0 0">
                            <Run Foreground="{DynamicResource BackgroundTextBrush}" Text="{DynamicResource 'In this mode RDP will start the session in the way mstsc.exe xxxx.rdp in CMD, it can offer more custom parameters.'}"></Run>
                        </TextBlock>
                        <TextBlock Width="500" TextWrapping="Wrap" Margin="0 5 0 0" Opacity="0.7">
                            <Run Foreground="{DynamicResource BackgroundTextBrush}" Text="{DynamicResource 'Note: This mode will be automatically enabled if there are 2+ monitors with different display scaling on your PC and you selected the full screen mode.'}"></Run>
                        </TextBlock>
                    </StackPanel>
                </StackPanel>
            </Grid>

            <StackPanel Visibility="{Binding New.MstscModeEnabled, Converter={StaticResource ConverterBool2Visible}}">
                <Grid Style="{StaticResource EditorRowGrid}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Style="{StaticResource EditorRowGridTitle}" 
                                   Text="{DynamicResource 'Additional settings'}" VerticalAlignment="Top" 
                                   Margin="0 7 30 0"></TextBlock>
                        <Grid Style="{StaticResource EditorRowGridInput}">
                            <Border>
                                <Border.Style>
                                    <Style TargetType="Border">
                                        <Setter Property="BorderThickness" Value="1" />
                                        <Setter Property="CornerRadius" Value="5" />
                                        <Setter Property="BorderBrush" Value="{DynamicResource DefaultBorderBrush}"/>
                                        <Setter Property="Padding" Value="5 1" />
                                        <Setter Property="Opacity" Value="1" />
                                        <Style.Triggers>
                                            <MultiDataTrigger>
                                                <MultiDataTrigger.Conditions>
                                                    <Condition Binding="{Binding ElementName=TextBoxRdpFileAdditionalSettings, Path=IsMouseOver}" Value="True"></Condition>
                                                    <Condition Binding="{Binding ElementName=TextBoxRdpFileAdditionalSettings, Path=TextArea.IsFocused}" Value="False"></Condition>
                                                </MultiDataTrigger.Conditions>
                                                <Setter Property="BorderBrush" Value="{DynamicResource AccentMidBrush}" />
                                                <Setter Property="Opacity" Value="0.6" />
                                            </MultiDataTrigger>
                                            <DataTrigger Binding="{Binding ElementName=TextBoxRdpFileAdditionalSettings, Path=TextArea.IsFocused}" Value="True">
                                                <Setter Property="BorderBrush" Value="{DynamicResource AccentMidBrush}" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Border.Style>
                            </Border>
                            <controls:BindableAvalonEditor Margin="8 0 4 0"
                                                           Padding="0 5 0 5"
                                                           x:Name="TextBoxRdpFileAdditionalSettings"
                                                           WordWrap="False"
                                                           ShowLineNumbers="True"
                                                           Text="{Binding New.RdpFileAdditionalSettings}"
                                                           FontSize="{DynamicResource TextFontSize}">
                                <controls:BindableAvalonEditor.Resources>
                                    <VisualBrush x:Key="HelpBrush" TileMode="None" Opacity="0.3" Stretch="None" AlignmentX="Left">
                                        <VisualBrush.Visual>
                                            <TextBlock Style="{StaticResource TextBlockBase}" FontStyle="Italic">tip e.g. selectedmonitors:s:0,2</TextBlock>
                                        </VisualBrush.Visual>
                                    </VisualBrush>
                                </controls:BindableAvalonEditor.Resources>
                                <controls:BindableAvalonEditor.Style>
                                    <Style TargetType="controls:BindableAvalonEditor" BasedOn="{StaticResource ControlBase}">
                                        <Setter Property="Validation.ErrorTemplate" Value="{StaticResource ErrorTemplate}" />
                                        <Setter Property="Foreground" Value="{DynamicResource BackgroundTextBrush}"/>
                                        <Setter Property="Background" Value="Transparent"/>
                                        <Style.Triggers>
                                            <Trigger Property="Text" Value="{x:Null}">
                                                <Setter Property="Background" Value="{StaticResource HelpBrush}"/>
                                            </Trigger>
                                            <Trigger Property="Text" Value="">
                                                <Setter Property="Background" Value="{StaticResource HelpBrush}"/>
                                            </Trigger>
                                        </Style.Triggers>
                                    </Style>
                                </controls:BindableAvalonEditor.Style>
                            </controls:BindableAvalonEditor>
                        </Grid>

                        <TextBlock Style="{StaticResource TextBlockBase}" VerticalAlignment="Top" Margin="2 0">
                            <Hyperlink NavigateUri="https://1remote.github.io/usage/protocol/especial/rdp-in-mstsc-mode/#additional-settings" TextDecorations="{x:Null}" 
                                       controls1:HyperlinkHelper.IsOpenExternal="True">
                                (?)
                            </Hyperlink>
                        </TextBlock>
                    </StackPanel>
                </Grid>
                <Grid Style="{StaticResource EditorRowGrid}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource 'Helper'}"></TextBlock>
                        <Grid>
                            <StackPanel Orientation="Horizontal">
                                <Button Click="ButtonPreviewRdpFile_OnClick" Margin="0 0 5 0" Content="{DynamicResource 'Preview rdp file'}"></Button>
                                <Button Click="ButtonShowMonitorsNum_OnClick" ToolTip="mstsc.exe /l" Content="{DynamicResource 'Check monitor number'}"></Button>
                            </StackPanel>
                        </Grid>
                    </StackPanel>
                </Grid>
            </StackPanel>
        </StackPanel>


        <StackPanel>
            <TextBlock Style="{StaticResource EditorGroupTextBlockTitle}" Text="{DynamicResource server_editor_group_title_advantage}"></TextBlock>


            <Grid Style="{StaticResource EditorRowGrid}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="/admin"></TextBlock>
                    <CheckBox HorizontalAlignment="Right" Margin="0 0 10 0" 
                              Content="{DynamicResource server_editor_advantage_admin}"
                              IsChecked="{Binding New.IsAdministrativePurposes}"></CheckBox>
                </StackPanel>
            </Grid>

            <Grid Style="{StaticResource EditorRowGrid}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource server_editor_advantage_sounds}"></TextBlock>
                    <Grid Style="{StaticResource EditorRowGridInput}">
                        <Grid.Resources>
                            <forms:ConverterEAudioRedirectionMode x:Key="ConverterEAudioRedirectionMode" />
                        </Grid.Resources>
                        <ComboBox SelectedIndex="{Binding New.AudioRedirectionMode, Converter={StaticResource ConverterEAudioRedirectionMode}}">
                            <ComboBoxItem Content="{DynamicResource server_editor_advantage_sounds_on_local}" ToolTip="{DynamicResource server_editor_advantage_sounds_on_local}" />
                            <ComboBoxItem Content="{DynamicResource server_editor_advantage_sounds_on_remote}" ToolTip="{DynamicResource server_editor_advantage_sounds_on_remote}" />
                            <ComboBoxItem Content="{DynamicResource server_editor_advantage_sounds_disabled}" ToolTip="{DynamicResource server_editor_advantage_sounds_disabled}" />
                            <ComboBoxItem Visibility="{Binding New.AudioRedirectionMode, Converter={StaticResource ConverterEqual2Visible}, ConverterParameter={x:Null}}" Content="{Binding New.ServerEditorDifferentOptions}" />
                        </ComboBox>
                    </Grid>
                </StackPanel>
            </Grid>

            <Grid Style="{StaticResource EditorRowGrid}" Visibility="{Binding New.AudioRedirectionMode, Converter={StaticResource ConverterEqual2Visible}, ConverterParameter={x:Static protocol:EAudioRedirectionMode.RedirectToLocal}}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource server_editor_advantage_sound_quality}"></TextBlock>
                    <Grid Style="{StaticResource EditorRowGridInput}">
                        <Grid.Resources>
                            <forms:ConverterEAudioQualityMode x:Key="ConverterEAudioQualityMode" />
                        </Grid.Resources>
                        <ComboBox SelectedIndex="{Binding New.AudioQualityMode, Converter={StaticResource ConverterEAudioQualityMode}}">
                            <ComboBoxItem Content="{DynamicResource server_editor_advantage_sound_quality_dynamic}" ToolTip="{DynamicResource server_editor_advantage_sound_quality_dynamic}" />
                            <ComboBoxItem Content="{DynamicResource server_editor_advantage_sound_quality_medium}" ToolTip="{DynamicResource server_editor_advantage_sound_quality_medium}" />
                            <ComboBoxItem Content="{DynamicResource server_editor_advantage_sound_quality_high}" ToolTip="{DynamicResource server_editor_advantage_sound_quality_high}" />
                            <ComboBoxItem Visibility="{Binding New.AudioQualityMode, Converter={StaticResource ConverterEqual2Visible}, ConverterParameter={x:Null}}" Content="{Binding New.ServerEditorDifferentOptions}" />
                        </ComboBox>
                    </Grid>
                </StackPanel>
            </Grid>

            <Grid Style="{StaticResource EditorRowGrid}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource server_editor_advantage_resources}"></TextBlock>
                    <UniformGrid Columns="3" Rows="3" Width="500" VerticalAlignment="Center" HorizontalAlignment="Center">
                        <UniformGrid.Resources>
                            <Style TargetType="CheckBox" BasedOn="{StaticResource CheckBoxAccentStyle}">
                                <Setter Property="Margin" Value="0 5"></Setter>
                            </Style>
                        </UniformGrid.Resources>
                        <CheckBox Content="{DynamicResource server_editor_advantage_clipboard}" IsChecked="{Binding New.EnableClipboard}"></CheckBox>
                        <CheckBox Content="{DynamicResource server_editor_advantage_key_combinations}" IsChecked="{Binding New.EnableKeyCombinations}"></CheckBox>
                        <CheckBox Content="{DynamicResource server_editor_advantage_audio_capture}" IsChecked="{Binding New.EnableAudioCapture}"></CheckBox>
                        <CheckBox Content="{DynamicResource server_editor_advantage_ports}" IsChecked="{Binding New.EnablePorts}"></CheckBox>
                        <CheckBox Content="{DynamicResource server_editor_advantage_printers}" IsChecked="{Binding New.EnablePrinters}"></CheckBox>
                        <CheckBox Content="{DynamicResource server_editor_advantage_smart_cards}" IsChecked="{Binding New.EnableSmartCardsAndWinHello}"></CheckBox>
                        <CheckBox Content="{DynamicResource server_editor_advantage_disk_drives}" IsChecked="{Binding New.EnableDiskDrives}"></CheckBox>
                        <CheckBox Content="{DynamicResource 'Drives plug in later'}" IsChecked="{Binding New.EnableRedirectDrivesPlugIn}"></CheckBox>
                        <CheckBox Content="{DynamicResource Cameras}" IsChecked="{Binding New.EnableRedirectCameras}"></CheckBox>
                    </UniformGrid>
                </StackPanel>
            </Grid>
        </StackPanel>


        <StackPanel>
            <StackPanel.Resources>
                <forms:ConverterEGatewayLogonMethod x:Key="ConverterEGatewayLogonMethod" />
            </StackPanel.Resources>

            <TextBlock Style="{StaticResource EditorGroupTextBlockTitle}" Text="{DynamicResource server_editor_group_title_gateway}"></TextBlock>

            <Grid Style="{StaticResource EditorRowGrid}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource server_editor_gateway_mode}"></TextBlock>
                    <Grid Style="{StaticResource EditorRowGridInput}">
                        <Grid.Resources>
                            <forms:ConverterEGatewayMode x:Key="ConverterEGatewayMode" />
                        </Grid.Resources>
                        <ComboBox SelectedIndex="{Binding New.GatewayMode, Converter={StaticResource ConverterEGatewayMode}}">
                            <ComboBoxItem Content="{DynamicResource server_editor_gateway_mode_automatically_detect}" ToolTip="{DynamicResource server_editor_display_rdp_performance_low}" />
                            <ComboBoxItem Content="{DynamicResource server_editor_gateway_mode_use_these}" ToolTip="{DynamicResource server_editor_display_rdp_performance_middle}" />
                            <ComboBoxItem Content="{DynamicResource server_editor_gateway_mode_do_not_use}" ToolTip="{DynamicResource server_editor_gateway_mode_do_not_use}" />
                            <ComboBoxItem Visibility="{Binding New.GatewayMode, Converter={StaticResource ConverterEqual2Visible}, ConverterParameter={x:Null}}" Content="{Binding New.ServerEditorDifferentOptions}" />
                        </ComboBox>
                    </Grid>
                </StackPanel>
            </Grid>

            <Grid>
                <Grid.Style>
                    <Style TargetType="Grid" BasedOn="{StaticResource EditorRowGrid}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding New.GatewayMode}" Value="{x:Static protocol:EGatewayMode.DoNotUseGateway}">
                                <Setter Property="Visibility" Value="Collapsed"></Setter>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding New.MstscModeEnabled}" Value="True">
                                <Setter Property="Visibility" Value="Collapsed"></Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Grid.Style>
                <StackPanel Margin="70 10 0 0">
                    <Grid Style="{StaticResource EditorRowGrid}" Margin="0 3 0 0">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource server_editor_gateway_server_host_name}"></TextBlock>
                            <TextBox Text="{Binding New.GatewayHostName, UpdateSourceTrigger=PropertyChanged}" Width="200"></TextBox>
                        </StackPanel>
                    </Grid>
                    <Grid Style="{StaticResource EditorRowGrid}" Margin="0 6 0 0">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource server_editor_gateway_logon_method}"></TextBlock>
                            <ComboBox SelectedIndex="{Binding New.GatewayLogonMethod, Converter={StaticResource ConverterEGatewayLogonMethod}}" Width="200">
                                <ComboBoxItem Content="{DynamicResource server_editor_gateway_logon_method_psw}" ToolTip="{DynamicResource server_editor_gateway_logon_method_psw}" />
                                <ComboBoxItem Content="{DynamicResource server_editor_gateway_logon_method_smart_card}" ToolTip="{DynamicResource server_editor_gateway_logon_method_smart_card}" />
                                <ComboBoxItem Visibility="{Binding New.GatewayLogonMethod, Converter={StaticResource ConverterEqual2Visible}, ConverterParameter={x:Null}}" Content="{Binding New.ServerEditorDifferentOptions}" />
                            </ComboBox>
                        </StackPanel>
                    </Grid>

                    <Grid Visibility="{Binding New.GatewayLogonMethod, Converter={StaticResource ConverterEqual2Collapsed}, ConverterParameter={x:Static protocol:EGatewayLogonMethod.SmartCard}}"
                          Style="{StaticResource EditorRowGrid}"
                          Margin="0 6 0 0">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource User}"></TextBlock>
                            <TextBox Text="{Binding New.GatewayUserName, UpdateSourceTrigger=PropertyChanged}" Width="200"></TextBox>
                        </StackPanel>
                    </Grid>

                    <Grid Visibility="{Binding New.GatewayLogonMethod, Converter={StaticResource ConverterEqual2Collapsed}, ConverterParameter={x:Static protocol:EGatewayLogonMethod.SmartCard}}"
                          Style="{StaticResource EditorRowGrid}"
                          Margin="0 6 0 0">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Style="{StaticResource EditorRowGridTitle}" Text="{DynamicResource Password}"></TextBlock>
                            <controls:PasswordInput Height="28" Password="{Binding New.GatewayPassword, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay }" Width="200"/>
                        </StackPanel>
                    </Grid>
                </StackPanel>
            </Grid>
        </StackPanel>


        <StackPanel Visibility="{Binding New.MstscModeEnabled, Converter={StaticResource ConverterBool2VisibleInv}}">
            <TextBlock Style="{StaticResource EditorGroupTextBlockTitle}" Text="MISC"></TextBlock>

            <Grid Style="{StaticResource EditorRowGrid}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Style="{StaticResource EditorRowGridTitle}" 
                               Text="{DynamicResource 'Additional settings'}" VerticalAlignment="Top" 
                               Margin="0 7 30 0"></TextBlock>
                    <StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <Grid Style="{StaticResource EditorRowGridInput}" Width="500">
                                <Border>
                                    <Border.Style>
                                        <Style TargetType="Border">
                                            <Setter Property="BorderThickness" Value="1" />
                                            <Setter Property="CornerRadius" Value="5" />
                                            <Setter Property="BorderBrush" Value="{DynamicResource DefaultBorderBrush}"/>
                                            <Setter Property="Padding" Value="5 1" />
                                            <Setter Property="Opacity" Value="1" />
                                            <Style.Triggers>
                                                <MultiDataTrigger>
                                                    <MultiDataTrigger.Conditions>
                                                        <Condition Binding="{Binding ElementName=TextBoxRdpControlAdditionalSettings, Path=IsMouseOver}" Value="True"></Condition>
                                                        <Condition Binding="{Binding ElementName=TextBoxRdpControlAdditionalSettings, Path=TextArea.IsFocused}" Value="False"></Condition>
                                                    </MultiDataTrigger.Conditions>
                                                    <Setter Property="BorderBrush" Value="{DynamicResource AccentMidBrush}" />
                                                    <Setter Property="Opacity" Value="0.6" />
                                                </MultiDataTrigger>
                                                <DataTrigger Binding="{Binding ElementName=TextBoxRdpControlAdditionalSettings, Path=TextArea.IsFocused}" Value="True">
                                                    <Setter Property="BorderBrush" Value="{DynamicResource AccentMidBrush}" />
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Border.Style>
                                </Border>
                                <controls:BindableAvalonEditor Margin="8 0 4 0"
                                                               Padding="0 5 0 5"
                                                               x:Name="TextBoxRdpControlAdditionalSettings"
                                                               WordWrap="False"
                                                               ShowLineNumbers="True"
                                                               Text="{Binding New.RdpControlAdditionalSettings, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, ValidatesOnNotifyDataErrors=True}"
                                                               FontSize="{DynamicResource TextFontSize}">
                                    <controls:BindableAvalonEditor.Resources>
                                        <VisualBrush x:Key="HelpBrush" TileMode="None" Opacity="0.3" Stretch="None" AlignmentX="Left">
                                            <VisualBrush.Visual>
                                                <TextBlock Style="{StaticResource TextBlockBase}" FontStyle="Italic" Margin="10 0 0 0">e.g. EnableAutoReconnect:i:0</TextBlock>
                                            </VisualBrush.Visual>
                                        </VisualBrush>
                                    </controls:BindableAvalonEditor.Resources>
                                    <controls:BindableAvalonEditor.Style>
                                        <Style TargetType="controls:BindableAvalonEditor" BasedOn="{StaticResource ControlBase}">
                                            <Setter Property="Validation.ErrorTemplate" Value="{StaticResource ErrorTemplate}" />
                                            <Setter Property="Foreground" Value="{DynamicResource BackgroundTextBrush}"/>
                                            <Setter Property="Background" Value="Transparent"/>
                                            <Style.Triggers>
                                                <Trigger Property="Text" Value="{x:Null}">
                                                    <Setter Property="Background" Value="{StaticResource HelpBrush}"/>
                                                </Trigger>
                                                <Trigger Property="Text" Value="">
                                                    <Setter Property="Background" Value="{StaticResource HelpBrush}"/>
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                    </controls:BindableAvalonEditor.Style>
                                </controls:BindableAvalonEditor>
                            </Grid>
                            <!--TODO: Add a link to the documentation
                            <TextBlock VerticalAlignment="Top" Margin="2 0">
                                <Hyperlink NavigateUri="https://1remote.github.io/usage/protocol/especial/rdp-in-mstsc-mode/#additional-settings" TextDecorations="{x:Null}" 
                                           controls1:HyperlinkHelper.IsOpenExternal="True">
                                    (?)
                                </Hyperlink>
                            </TextBlock>-->
                        </StackPanel>


                        <TextBlock Style="{StaticResource TextBlockBase}" Width="500" TextWrapping="Wrap" Margin="0 5 0 0">
                            <Run Foreground="{DynamicResource BackgroundTextBrush}" Text="Here you can set options not listed in the UI, enabling richer configuration possibilities, such as disabling automatic reconnection by `EnableAutoReconnect:i:0`, or disabling combination keys by `HotKeyAltTab:i:0`, or pin the connection bar by `PinConnectionBar:i:1`."></Run>
                        </TextBlock>
                        <TextBlock Style="{StaticResource TextBlockBase}" Width="500" TextWrapping="Wrap" Margin="0 5 0 0" Opacity="0.7">
                            <Run Foreground="{DynamicResource BackgroundTextBrush}" Text=" Note that this option has the highest priority and will override previous configurations from UI."></Run>
                        </TextBlock>

                    </StackPanel>
                </StackPanel>
            </Grid>
        </StackPanel>


        <Grid Style="{StaticResource EditorRowGrid}">
        </Grid>
    </StackPanel>
</UserControl>