<UserControl x:Class="_1RM.View.Editor.ServerEditorPageView"
             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:system="clr-namespace:System;assembly=mscorlib"
             xmlns:controls="clr-namespace:_1RM.Controls"
             xmlns:icons="clr-namespace:_1RM.Resources.Icons"
             xmlns:attachProperty="clr-namespace:Shawn.Utils.WpfResources.Theme.AttachProperty;assembly=Shawn.Utils.WpfResources"
             xmlns:colorPickerWpf="clr-namespace:ColorPickerWPF;assembly=Shawn.Utils.Wpf"
             xmlns:controls1="clr-namespace:Shawn.Utils.Wpf.Controls;assembly=Shawn.Utils.Wpf"
             xmlns:editor="clr-namespace:_1RM.View.Editor"
             xmlns:noteDisplay="clr-namespace:_1RM.Controls.NoteDisplay"
             xmlns:dao="clr-namespace:_1RM.Service.DataSource.DAO"
             xmlns:s="https://github.com/canton7/Stylet"
             xmlns:controls2="clr-namespace:WpfToolkit.Controls;assembly=VirtualizingWrapPanel"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance editor:ServerEditorPageViewModel}"
             Background="White"
             d:DesignHeight="1000" d:DesignWidth="800">

    <Grid Background="{DynamicResource BackgroundBrush}" ClipToBounds="True">
        <Grid.Resources>
            <system:Double x:Key="TopHeight">20</system:Double>
            <system:Double x:Key="BottomHeight">40</system:Double>
        </Grid.Resources>
        <Grid>
            <Grid.Resources>
                <Style TargetType="TextBlock" x:Key="RowHeader" BasedOn="{StaticResource TextBlockBase}">
                    <Setter Property="Foreground" Value="{DynamicResource BackgroundTextBrush}"></Setter>
                    <Setter Property="MinWidth" Value="150"></Setter>
                    <Setter Property="VerticalAlignment" Value="Center"></Setter>
                    <Setter Property="HorizontalAlignment" Value="Left"></Setter>
                    <Setter Property="TextAlignment" Value="Right"></Setter>
                    <Setter Property="TextWrapping" Value="WrapWithOverflow"></Setter>
                    <Setter Property="Margin">
                        <Setter.Value>
                            <Thickness Right="30"></Thickness>
                        </Setter.Value>
                    </Setter>
                </Style>
                <Style TargetType="controls:GridWith4Columns">
                    <Setter Property="Height" Value="Auto"></Setter>
                    <Setter Property="MinHeight" Value="30"></Setter>
                    <Setter Property="Margin">
                        <Setter.Value>
                            <Thickness Bottom="0" Top="15"></Thickness>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Grid.Resources>
            <Grid.Margin>
                <Thickness Top="{StaticResource TopHeight}" Bottom="{StaticResource BottomHeight}"></Thickness>
            </Grid.Margin>

            <ScrollViewer Grid.IsSharedSizeScope="True"
                          x:Name="ScrollViewerMain"
                          Margin="0 3 0 4"
                          HorizontalScrollBarVisibility="Disabled"
                          VerticalScrollBarVisibility="Auto">
                <Grid>
                    <StackPanel Orientation="Vertical">
                        <TextBlock Style="{StaticResource EditorGroupTextBlockTitle}" Text="{DynamicResource server_editor_group_title_common}"></TextBlock>


                        <Grid>
                            <StackPanel Orientation="Vertical">
                                <controls:GridWith4Columns>
                                    <TextBlock Grid.Column="0" Text="{DynamicResource Name}" Style="{StaticResource RowHeader}"></TextBlock>
                                    <controls:AutoCompleteComboBox Grid.Column="1"
                                                                   Text="{Binding Server.DisplayName, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True, ValidatesOnNotifyDataErrors=True}"
                                                                   Selections="{Binding NameSelections, Mode=OneTime}"/>
                                </controls:GridWith4Columns>


                                <controls:GridWith4Columns>
                                    <TextBlock Style="{StaticResource RowHeader}" Grid.Column="0" Text="{DynamicResource Icon}"></TextBlock>

                                    <StackPanel Grid.Column="1" Orientation="Horizontal">
                                        <Grid Name="GridLogo" Width="64" Height="64"
                                              Background="Transparent"
                                              Cursor="Hand"
                                              Margin="0 0 30 0">
                                            <Border BorderThickness="1" CornerRadius="{StaticResource DefaultCornerRadius}" 
                                                    ClipToBounds="True">
                                                <Border.Style>
                                                    <Style TargetType="Border">
                                                        <Setter Property="BorderBrush" Value="{DynamicResource DefaultBorderBrush}"/>
                                                        <Style.Triggers>
                                                            <DataTrigger Binding="{Binding ElementName=GridLogo, Path=IsMouseOver}" Value="True">
                                                                <Setter Property="BorderBrush" Value="{DynamicResource AccentMidBrush}"></Setter>
                                                            </DataTrigger>
                                                        </Style.Triggers>
                                                    </Style>
                                                </Border.Style>
                                                <Grid>
                                                    <Image Height="64" Width="64" Source="{Binding Server.IconImg}" ></Image>

                                                    <Button Background="{DynamicResource BackgroundBrush}" Opacity="0.9"
                                                            Command="{Binding CmdSelectImage}"
                                                            BorderThickness="0"
                                                    >
                                                        <Button.Style>
                                                            <Style TargetType="Button" BasedOn="{StaticResource ButtonBarBackgroundStyle}">
                                                                <Setter Property="Visibility" Value="Collapsed"></Setter>
                                                                <Style.Triggers>
                                                                    <DataTrigger Binding="{Binding ElementName=GridLogo, Path=IsMouseOver}" Value="True">
                                                                        <Setter Property="Visibility" Value="Visible"></Setter>
                                                                    </DataTrigger>
                                                                </Style.Triggers>
                                                            </Style>
                                                        </Button.Style>
                                                        <Path Data="F1 M 10 18.75 C 11.002604 18.75 11.964518 18.595377 12.885742 18.286133 C 13.806965 17.976889 14.646809 17.540689 15.405273 16.977539 C 16.163736 16.414389 16.824543 15.737305 17.387695 14.946289 C 17.950846 14.155273 18.378906 13.277995 18.671875 12.314453 L 19.863281 12.685547 C 19.53776 13.772787 19.052734 14.763998 18.408203 15.65918 C 17.763672 16.554361 17.006836 17.324219 16.137695 17.96875 C 15.268555 18.613281 14.311523 19.112955 13.266602 19.467773 C 12.22168 19.822592 11.132812 20 10 20 C 9.108072 20 8.238932 19.889322 7.392578 19.667969 C 6.546224 19.446615 5.74707 19.125977 4.995117 18.706055 C 4.243164 18.286133 3.548177 17.775064 2.910156 17.172852 C 2.272135 16.570639 1.71875 15.888672 1.25 15.126953 L 1.25 17.5 L 0 17.5 L 0 12.5 L 5 12.5 L 5 13.75 L 1.914062 13.75 C 2.298177 14.511719 2.775065 15.200195 3.344727 15.81543 C 3.914388 16.430664 4.550781 16.954752 5.253906 17.387695 C 5.957031 17.820639 6.710612 18.155924 7.514648 18.393555 C 8.318685 18.631186 9.147135 18.75 10 18.75 Z M 20 2.5 L 20 7.5 L 15 7.5 L 15 6.25 L 18.085938 6.25 C 17.701822 5.488281 17.224934 4.799805 16.655273 4.18457 C 16.085611 3.569336 15.449219 3.045248 14.746094 2.612305 C 14.042969 2.179363 13.289388 1.844076 12.485352 1.606445 C 11.681314 1.368816 10.852864 1.25 10 1.25 C 8.997396 1.25 8.035481 1.404623 7.114258 1.713867 C 6.193034 2.023113 5.35319 2.459311 4.594727 3.022461 C 3.836263 3.585613 3.175456 4.262695 2.612305 5.053711 C 2.049154 5.844727 1.621094 6.722006 1.328125 7.685547 L 0.136719 7.314453 C 0.46224 6.233725 0.947266 5.244141 1.591797 4.345703 C 2.236328 3.447266 2.993164 2.675781 3.862305 2.03125 C 4.731445 1.386719 5.688477 0.887045 6.733398 0.532227 C 7.77832 0.17741 8.867188 0 10 0 C 10.891927 0 11.761067 0.110678 12.607422 0.332031 C 13.453775 0.553387 14.25293 0.874023 15.004883 1.293945 C 15.756836 1.713867 16.451822 2.224936 17.089844 2.827148 C 17.727863 3.429363 18.28125 4.111328 18.75 4.873047 L 18.75 2.5 Z " 
                                                              StrokeThickness="1"
                                                              Stroke="{DynamicResource BackgroundTextBrush}"
                                                              Fill="{DynamicResource BackgroundTextBrush}" 
                                                              Stretch="Uniform" 
                                                              Width="30"
                                                        />
                                                    </Button>
                                                </Grid>
                                            </Border>
                                        </Grid>
                                        <TextBlock Style="{StaticResource EditorRowGridTitle}" Width="50" Text="{DynamicResource Color}"></TextBlock>
                                        <colorPickerWpf:ColorPickRowPopup HexColor="{Binding Server.ColorHex}"
                                                                          Foreground="{DynamicResource BackgroundTextBrush}" 
                                                                          HexVisible="Collapsed"
                                                                          Name="ColorPick" HorizontalAlignment="Left" VerticalAlignment="Center" />
                                        <TextBlock Style="{StaticResource EditorRowGridTitle}" Width="Auto" HorizontalAlignment="Left" 
                                                   Text="{Binding Server.ColorHex}"></TextBlock>
                                    </StackPanel>
                                </controls:GridWith4Columns>





                                <controls:GridWith4Columns>
                                    <CheckBox IsChecked="{Binding Server.AlwaysOpenInNewTabWindow}" Grid.Column="1" Content="{DynamicResource 'Always open in new window'}"></CheckBox>
                                </controls:GridWith4Columns>



                                <controls:GridWith4Columns>
                                    <TextBlock Grid.Column="0" Text="{DynamicResource Tags}" Style="{StaticResource RowHeader}"></TextBlock>
                                    <controls:TagsEditor x:Name="TagsEditor" Grid.Column="1" 
                                                         Tags="{Binding Server.Tags, Mode=TwoWay}"
                                                         TagsForSelect="{Binding TagSelections, Mode=OneTime}"></controls:TagsEditor>
                                </controls:GridWith4Columns>

                                <StackPanel Orientation="Horizontal" Margin="0 5 0 0">
                                    <TextBlock Text="" Style="{StaticResource RowHeader}"></TextBlock>
                                    <TextBlock MaxWidth="600"
                                               Style="{StaticResource TextBlockBase}"
                                               Text="{DynamicResource 'Press Enter to add a tag, which is used for grouping servers. By right-clicking on the tags on the homepage, you can filter or pin a specific tag.'}"
                                               TextWrapping="WrapWithOverflow" 
                                               Opacity="0.5"></TextBlock>
                                </StackPanel>



                                <controls:GridWith4Columns>
                                    <TextBlock Style="{StaticResource RowHeader}" Grid.Column="0" Text="{DynamicResource 'Script before connect'}"></TextBlock>
                                    <TextBox Grid.Column="1"
                                             Text="{Binding Server.CommandBeforeConnected, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True}"
                                             ToolTip="{DynamicResource 'Run bat before connect'}"
                                             Tag="{DynamicResource 'Run bat before connect'}"/>
                                    <StackPanel Grid.Column="2" Orientation="Horizontal">
                                        <Button Margin="5 0 0 0" 
                                                VerticalAlignment="Stretch"
                                                Command="{Binding CmdSelectScript}" CommandParameter="before"
                                                Style="{StaticResource ButtonPrimaryStyle}" 
                                                Content="{DynamicResource Select}"></Button>

                                        <Button Margin="5 0 0 0" 
                                                VerticalAlignment="Stretch"
                                                Command="{Binding CmdTestScript}" CommandParameter="before"
                                                Style="{StaticResource ButtonPrimaryStyle}" 
                                                Content="{DynamicResource Test}"></Button>
                                    </StackPanel>
                                </controls:GridWith4Columns>

                                <StackPanel Orientation="Horizontal" Margin="0 5 0 0">
                                    <TextBlock Text="" Style="{StaticResource RowHeader}"></TextBlock>
                                    <CheckBox VerticalContentAlignment="Top"
                                              MaxWidth="600"
                                              IsChecked="{Binding Server.HideCommandBeforeConnectedWindow}" 
                                              ToolTip="{DynamicResource 'Hide script window'}">
                                        <TextBlock Text="{DynamicResource 'Hide script window'}"
                                                   TextWrapping="WrapWithOverflow" 
                                                   Opacity="0.5"></TextBlock>
                                    </CheckBox>
                                </StackPanel>



                                <controls:GridWith4Columns>
                                    <TextBlock Style="{StaticResource RowHeader}" Grid.Column="0" Text="{DynamicResource 'Script after disconnected'}"></TextBlock>
                                    <TextBox Grid.Column="1"
                                             Text="{Binding Server.CommandAfterDisconnected, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True}"
                                             ToolTip="{DynamicResource 'Run bat after disconnected'}"
                                             Tag="{DynamicResource 'Run bat after disconnected'}"></TextBox>
                                    <StackPanel Grid.Column="2" Orientation="Horizontal">
                                        <Button Margin="5 0 0 0" 
                                                VerticalAlignment="Stretch"
                                                Command="{Binding CmdSelectScript}" CommandParameter="after"
                                                Style="{StaticResource ButtonPrimaryStyle}" 
                                                Content="{DynamicResource Select}"></Button>

                                        <Button Margin="5 0 0 0" 
                                                VerticalAlignment="Stretch"
                                                Command="{Binding CmdTestScript}" CommandParameter="after"
                                                Style="{StaticResource ButtonPrimaryStyle}" 
                                                Content="{DynamicResource Test}"></Button>
                                    </StackPanel>
                                </controls:GridWith4Columns>

                                <controls:GridWith4Columns>
                                    <controls:GridWith4Columns.Style>
                                        <Style TargetType="controls:GridWith4Columns" BasedOn="{StaticResource {x:Type controls:GridWith4Columns}}">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding Runners.Count}" Value="0">
                                                    <Setter Property="Visibility" Value="Collapsed"></Setter>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </controls:GridWith4Columns.Style>
                                    <TextBlock Style="{StaticResource RowHeader}" Grid.Column="0" Text="{DynamicResource 'Selected runner'}"></TextBlock>

                                    <ComboBox Grid.Column="1" 
                                              ItemsSource="{Binding Runners, UpdateSourceTrigger=PropertyChanged}"
                                              SelectedItem="{Binding Server.SelectedRunnerName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                                    </ComboBox>
                                </controls:GridWith4Columns>

                                <!--<ContentControl Content="{Binding ProtocolEditControl}"></ContentControl>-->
                                <ContentControl s:View.Model="{Binding EditorViewModel}"></ContentControl>
                            </StackPanel>
                        </Grid>
                    </StackPanel>


                    <controls:GridWith4Columns VerticalAlignment="Top" MinHeight="60">
                        <Grid Margin="40 32" Grid.Column="2" Grid.ColumnSpan="2">
                            <StackPanel>
                                <StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
                                    <TextBlock Style="{StaticResource RowHeader}" Text="{DynamicResource Note}" TextAlignment="Center"></TextBlock>

                                    <!--icon button show note-->
                                    <Button Name="ButtonShowNote"
                                            Width="16" Height="16"
                                            Background="Transparent"
                                            attachProperty:VisionElement.BackgroundAccent="Transparent"
                                            attachProperty:VisionElement.BackgroundOnMouseDown="Transparent"
                                            Foreground="{DynamicResource BackgroundTextBrush}"
                                            attachProperty:VisionElement.ForegroundAccent="{DynamicResource BackgroundTextBrush}"
                                            attachProperty:VisionElement.ForegroundOnMouseDown="{DynamicResource BackgroundTextBrush}"
                                            HorizontalAlignment="Right" VerticalAlignment="Center"
                                            Opacity="0.7"
                                            ToolTip="{DynamicResource Preview}"
                                            attachProperty:VisionElement.Opacity="0.8"
                                            attachProperty:VisionElement.OpacityAccent="0.9"
                                            MouseEnter="ButtonShowNote_OnMouseEnter"
                                            Style="{StaticResource ButtonBarPrimaryStyle}"
                                            Visibility="{Binding Server.Note, Converter={StaticResource ConverterNoteToVisibility}}"
                                            >
                                        <Path Data="{StaticResource NoteGeometry}"
                                              Width="13"
                                              Stroke="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType=Button}}"
                                              Fill="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType=Button}}"
                                              StrokeThickness="0" Stretch="Uniform" />
                                    </Button>

                                    <Popup Name="PopupNote" 
                                           AllowsTransparency="True"
                                           PlacementTarget="{Binding ElementName=ButtonShowNote}" StaysOpen="False">
                                        <noteDisplay:NoteDisplayAndEditor x:Name="PopupNoteGrid" Width="400" Height="300"
                                                                          Server="{Binding Server, Mode=OneWay}"
                                                                          EditEnable="False"
                                                                          EditButtonVisibility="Collapsed"
                                                                          CloseButtonVisibility="Collapsed"/>
                                    </Popup>
                                </StackPanel>


                                <TextBox TextWrapping="Wrap" Width="Auto"
                                         TextAlignment="Left" Height="150" Margin="0 5"
                                         MouseWheel="TextBoxMarkdown_OnMouseWheel"
                                         VerticalContentAlignment="Top"
                                         AcceptsReturn="True"
                                         AcceptsTab="True"
                                         Tag="&#13;# Markdown support&#13;&#13;- write your note here&#13;- foo&#13;&#13;![pic](http://x/structure.png)&#13;&#13;[link](http://x/readme.md)" xml:space="preserve"
                                         Text="{Binding Server.Note, UpdateSourceTrigger=PropertyChanged}"></TextBox>
                            </StackPanel>
                        </Grid>
                    </controls:GridWith4Columns>
                </Grid>
            </ScrollViewer>
        </Grid>


        <!-- bulk editing flag-->
        <StackPanel Width="400" HorizontalAlignment="Right" VerticalAlignment="Top" 
                    ToolTip="{Binding Title}"
                    RenderTransformOrigin="0.5,0.5" 
                    Margin="0,35,-130,0" Background="{DynamicResource AccentMidBrush}">
            <StackPanel.Style>
                <Style TargetType="StackPanel">
                    <Setter Property="Visibility" Value="Collapsed"></Setter>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Title}" Value="">
                            <Setter Property="Visibility" Value="Collapsed"></Setter>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding ProtocolList.Count}" Value="0">
                            <Setter Property="Visibility" Value="Visible"></Setter>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </StackPanel.Style>
            <StackPanel.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="42.671"/>
                    <TranslateTransform X="15.43885806483096" Y="16.392014547605541"/>
                </TransformGroup>
            </StackPanel.RenderTransform>
            <StackPanel.Effect>
                <DropShadowEffect Color="Black" BlurRadius="10" Direction="0" ShadowDepth="2" Opacity="0.7" RenderingBias="Performance">
                </DropShadowEffect>
            </StackPanel.Effect>
            <TextBlock Style="{StaticResource TextBlockBase}" Name="TbServerType" Opacity="0.9"
                       FontWeight="Bold" Text="{DynamicResource server_editor_bulk_editing}" 
                       Margin="0 5"
                       Width="100"
                       TextAlignment="Center"
                       Foreground="{DynamicResource AccentTextBrush}"
                       HorizontalAlignment="Center" VerticalAlignment="Center">
                <TextBlock.FontSize>
                    <MultiBinding Converter="{StaticResource ConverterTextWidthAndContent2PresentationSize}" ConverterParameter="FontSize">
                        <Binding RelativeSource="{RelativeSource Self}" Path="Text"></Binding>
                        <Binding RelativeSource="{RelativeSource Self}" Path="Width"></Binding>
                        <Binding RelativeSource="{RelativeSource Self}" Path="FontFamily"></Binding>
                        <Binding RelativeSource="{RelativeSource Self}" Path="FontStyle"></Binding>
                        <Binding RelativeSource="{RelativeSource Self}" Path="FontWeight"></Binding>
                        <Binding RelativeSource="{RelativeSource Self}" Path="FontStretch"></Binding>
                    </MultiBinding>
                </TextBlock.FontSize>
            </TextBlock>
        </StackPanel>


        <Grid VerticalAlignment="Top">
            <Border BorderThickness="0 0 0 1" BorderBrush="{DynamicResource AccentMidBrush}" Background="{DynamicResource PrimaryTextBrush}" Height="{StaticResource TopHeight}">
                <Border.Effect>
                    <DropShadowEffect ShadowDepth="3" Direction="270"  Opacity="0.6" Color="Black"></DropShadowEffect>
                </Border.Effect>
            </Border>

            <Border BorderThickness="0 0 0 2" BorderBrush="{DynamicResource AccentMidBrush}" Background="{DynamicResource PrimaryMidBrush}">
                <Grid MinHeight="{StaticResource TopHeight}">
                    <!-- buck edit title -->
                    <TextBlock Foreground="{DynamicResource PrimaryTextBrush}" 
                               Margin="50 0" TextTrimming="CharacterEllipsis"
                               Text="{Binding Title}"
                               ToolTip="{Binding Title}"
                               VerticalAlignment="Center" HorizontalAlignment="Center">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock" BasedOn="{StaticResource TextBlockBase}">
                                <Setter Property="Visibility" Value="Collapsed"></Setter>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsBuckEdit}" Value="True">
                                        <Setter Property="Visibility" Value="Visible"></Setter>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>

                    </TextBlock>

                    <!-- protocols list -->
                    <ScrollViewer HorizontalScrollBarVisibility="Auto"
                                  Height="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType=Grid}, Path=Height}"
                                  controls1:ScrollViewerExtensions.IsHorizontalScrollOnWheelEnabled="true"
                                  attachProperty:VisionElement.ForegroundAccent="{DynamicResource PrimaryTextBrush}"
                                  attachProperty:VisionElement.BackgroundAccent="{DynamicResource PrimaryTextBrush}">
                        <ScrollViewer.Style>
                            <Style TargetType="ScrollViewer" BasedOn="{StaticResource ScrollViewMiniStyle}">
                                <Setter Property="Visibility" Value="Visible"></Setter>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsBuckEdit}" Value="True">
                                        <Setter Property="Visibility" Value="Collapsed"></Setter>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </ScrollViewer.Style>
                        <StackPanel Orientation="Horizontal">
                            <ListBox Name="ListBoxProtocols"
                                     IsSynchronizedWithCurrentItem="True"
                                     ItemsSource="{Binding ProtocolList}"
                                     SelectedValue="{Binding SelectedProtocol}"
                                     Background="{StaticResource PrimaryMidBrush}"
                                     Height="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType=ScrollViewer}, Path=Height}"
                                     ScrollViewer.VerticalScrollBarVisibility="Hidden"
                                     ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                                     BorderThickness="0"
                                     Margin="0"
                                     Padding="0">
                                <ListBox.Style>
                                    <Style TargetType="ListBox">
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="ListBox">
                                                    <ItemsPresenter />
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </ListBox.Style>
                                <ListBox.Resources>
                                    <Style TargetType="ListBoxItem">
                                        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                                        <Setter Property="Foreground" Value="{StaticResource PrimaryTextBrush}"></Setter>
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="ListBoxItem">
                                                    <Border BorderThickness="0" Margin="{TemplateBinding Margin}"
                                                            Padding="{TemplateBinding Control.Padding}"
                                                            Background="{TemplateBinding Panel.Background}"
                                                            Name="Bd"
                                                            SnapsToDevicePixels="True">
                                                        <ContentPresenter Content="{TemplateBinding ContentControl.Content}"
                                                                          ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
                                                                          ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"
                                                                          HorizontalAlignment="Center"
                                                                          VerticalAlignment="Center"
                                                                          SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                                                    </Border>
                                                    <ControlTemplate.Triggers>
                                                        <Trigger Property="Selector.IsSelected" Value="True">
                                                            <Setter Property="Opacity" TargetName="Bd" Value="1"></Setter>
                                                            <Setter Property="Background" TargetName="Bd" Value="{DynamicResource AccentMidBrush}"></Setter>
                                                            <Setter Property="Foreground" Value="{StaticResource AccentTextBrush}"></Setter>
                                                        </Trigger>
                                                        <MultiTrigger>
                                                            <MultiTrigger.Conditions>
                                                                <Condition Property="Selector.IsSelected" Value="False"></Condition>
                                                                <Condition Property="UIElement.IsMouseOver" Value="True"></Condition>
                                                            </MultiTrigger.Conditions>
                                                            <MultiTrigger.Setters>
                                                                <Setter Property="Background" TargetName="Bd" Value="{DynamicResource AccentLightBrush}"></Setter>
                                                                <Setter Property="Foreground" Value="{StaticResource AccentTextBrush}"></Setter>
                                                            </MultiTrigger.Setters>
                                                        </MultiTrigger>
                                                    </ControlTemplate.Triggers>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </ListBox.Resources>
                                <ListBox.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Horizontal"></StackPanel>
                                    </ItemsPanelTemplate>
                                </ListBox.ItemsPanel>

                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal" Margin="15 0">
                                            <TextBlock Style="{StaticResource TextBlockBase}"
                                                       Foreground="{Binding Path=Foreground,RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"
                                                       FontWeight="{Binding Path=FontWeight,RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"
                                                       Text="{Binding ProtocolDisplayName}"></TextBlock>
                                            <TextBlock Margin="5 0 0 0" 
                                                       Opacity="0.7"
                                                       Foreground="{Binding Path=Foreground,RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}">
                                                <TextBlock.Style>
                                                    <Style TargetType="TextBlock" BasedOn="{StaticResource TextBlockBase}">
                                                        <Style.Triggers>
                                                            <DataTrigger Value="" Binding="{Binding HelpUrl}">
                                                                <Setter Property="Visibility" Value="Collapsed"></Setter>
                                                            </DataTrigger>
                                                        </Style.Triggers>
                                                    </Style>
                                                </TextBlock.Style>
                                                <Hyperlink NavigateUri="{Binding HelpUrl}" 
                                                           Foreground="{Binding Path=Foreground,RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"
                                                           TextDecorations="{x:Null}" controls1:HyperlinkHelper.IsOpenExternal="True">
                                                    ?
                                                </Hyperlink>
                                            </TextBlock>
                                        </StackPanel>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ListBox>
                        </StackPanel>
                    </ScrollViewer>
                </Grid>
            </Border>
        </Grid>

        <Grid VerticalAlignment="Bottom">
            <Border BorderThickness="0 0 0 1" BorderBrush="{DynamicResource AccentMidBrush}" Background="{DynamicResource PrimaryTextBrush}" Height="{StaticResource BottomHeight}">
                <Border.Effect>
                    <DropShadowEffect ShadowDepth="3" Direction="90"  Opacity="0.6" Color="Black"></DropShadowEffect>
                </Border.Effect>
            </Border>

            <Border BorderThickness="0 2 0 0" BorderBrush="{DynamicResource AccentMidBrush}" Background="{DynamicResource PrimaryMidBrush}">
                <Grid Height="{StaticResource BottomHeight}">
                    <Grid Width="300">
                        <Button Name="ButtonSave" MinWidth="80" MinHeight="25"
                                Padding="0 1 0 0"
                                HorizontalAlignment="Left"
                                attachProperty:VisionElement.BorderBrushOnMouseOver="{DynamicResource AccentMidBrush}"
                                attachProperty:VisionElement.BorderBrushOnMouseDown="{DynamicResource AccentMidBrush}"
                                Command="{Binding CmdSave}"
                                Style="{StaticResource ButtonPrimaryStyle}">
                            <StackPanel Orientation="Horizontal" Margin="0 0 5 0">
                                <Border Height="16" Width="16" CornerRadius="2" Margin="0 0 5 0">
                                    <Border.Style>
                                        <Style TargetType="Border">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding Server.DataSource.Status}" Value="{x:Static dao:EnumDatabaseStatus.OK}">
                                                    <Setter Property="Visibility" Value="Collapsed"></Setter>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Border.Style>
                                    <Path Fill="Red" Height="14" Width="14" UseLayoutRounding="True" Stretch="Uniform" Data="{StaticResource GeometryCloudDisconnected}"/>
                                </Border>
                                <TextBlock Style="{StaticResource TextBlockBase}" Text="{DynamicResource Save}" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Foreground}"></TextBlock>
                            </StackPanel>
                        </Button>

                        <Button Padding="0 1 0 0" MinWidth="80" MinHeight="25"
                                HorizontalAlignment="Right"
                                Command="{Binding CmdCancel}"
                                Style="{StaticResource ButtonPrimaryStyle}"
                                Content="{DynamicResource Cancel}">
                        </Button>
                    </Grid>
                </Grid>
            </Border>
        </Grid>
    </Grid>
</UserControl>