<UserControl x:Class="_1RM.View.ServerList.ServerListPageView"
             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:view="clr-namespace:_1RM.View"
             xmlns:controls="clr-namespace:_1RM.Controls"
             xmlns:controls1="clr-namespace:Shawn.Utils.Wpf.Controls;assembly=Shawn.Utils.Wpf"
             xmlns:model="clr-namespace:_1RM.Model"
             xmlns:attachProperty="clr-namespace:Shawn.Utils.WpfResources.Theme.AttachProperty;assembly=Shawn.Utils.WpfResources"
             xmlns:s="https://github.com/canton7/Stylet"
             xmlns:controls2="clr-namespace:WpfToolkit.Controls;assembly=VirtualizingWrapPanel"
             xmlns:serverList="clr-namespace:_1RM.View.ServerList"
             xmlns:dao="clr-namespace:_1RM.Service.DataSource.DAO"
             xmlns:locality="clr-namespace:_1RM.Service.Locality"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance serverList:ServerListPageViewModel}"
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <CollectionViewSource x:Key="ServerListItemSource" 
                                  Source="{Binding VmServerList}"
                                  Filter="ServerListItemSource_OnFilter">
            </CollectionViewSource>


            <Style TargetType="{x:Type Expander}" BasedOn="{StaticResource ExpanderWithAnEye}"></Style>



            <system:Double x:Key="ServerItemHeight">40</system:Double>



            <Style TargetType="ListBoxItem">
                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListBoxItem">
                            <Grid Name="Grid" FocusVisualStyle="{x:Null}" 
                                  Background="{DynamicResource BackgroundBrush}"
                                  Visibility="{Binding Server.Id, Converter={StaticResource ConverterEqual2Collapsed}, ConverterParameter='0'}">

                                <Border x:Name="GridContainer"></Border>
                                <ContentPresenter Content="{TemplateBinding ContentControl.Content}"
                                                  ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
                                                  ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"
                                                  HorizontalAlignment="Stretch"
                                                  VerticalAlignment="Stretch"
                                                  SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="IsSelected" Value="True" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <!--drop effect-->
                <Setter Property="AllowDrop" Value="true"/>
                <EventSetter Event="MouseMove" Handler="ServerList_PreviewMouseMoveEvent"/>
                <EventSetter Event="Drop" Handler="ServerList_OnDrop"/>
                <!--drop end event-->
            </Style>

            <DataTemplate x:Key="DataTemplateForServerCards" DataType="view:ProtocolBaseViewModel">
                <Grid Visibility="{Binding IsVisible, Converter={StaticResource ConverterBool2Visible}}"
                      Height="164" Width="165">
                    <controls:ServerCardItem ProtocolBaseViewModel="{Binding}">
                    </controls:ServerCardItem>
                </Grid>
            </DataTemplate>


            <DataTemplate x:Key="DataTemplateForServerList" DataType="view:ProtocolBaseViewModel">
                <Grid Name="Grid" FocusVisualStyle="{x:Null}" Background="{DynamicResource BackgroundBrush}">
                    <Grid.InputBindings>
                        <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding CmdConnServer}"></MouseBinding>
                        <MouseBinding MouseAction="RightClick" Command="{Binding CmdEditServer}"></MouseBinding>
                    </Grid.InputBindings>
                    <Border x:Name="GridContainer"></Border>
                    <controls:ServerLineItem ProtocolBaseViewModel="{Binding}" 
                                             MinHeight="{StaticResource ServerItemHeight}"
                                             Visibility="{Binding IsVisible, Converter={StaticResource ConverterBool2Visible}}"
                                             ></controls:ServerLineItem>
                </Grid>
                <DataTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" TargetName="GridContainer" Value="{DynamicResource PrimaryTextBrush}"></Setter>
                        <Setter Property="Opacity" Value="0.2" TargetName="GridContainer" />
                    </Trigger>
                </DataTemplate.Triggers>
            </DataTemplate>

            <Style x:Key="ServerListStyle" TargetType="ListBox">
                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                <Setter Property="ItemTemplate" Value="{StaticResource DataTemplateForServerList}"></Setter>
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel IsVirtualizing="True"
                                                    ScrollUnit="Pixel"
                                                    VirtualizationMode="Recycling"
                                                    CacheLengthUnit="Item"
                                                    Margin="0 0 0 30"/>
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>

                <Setter Property="Margin">
                    <Setter.Value>
                        <Thickness Top="{StaticResource ServerItemHeight}"></Thickness>
                    </Setter.Value>
                </Setter>

                <Style.Triggers>
                    <DataTrigger Binding="{Binding ListPageIsCardView}" Value="True">
                        <Setter Property="ItemsPanel">
                            <Setter.Value>
                                <ItemsPanelTemplate>
                                    <controls2:VirtualizingWrapPanel IsVirtualizing="True"
                                                                     ScrollUnit="Item"
                                                                     SpacingMode="None"
                                                                     Margin="15 10 0 20"
                                                                     Width="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType=ListBox}, Path=ActualWidth}"></controls2:VirtualizingWrapPanel>
                                </ItemsPanelTemplate>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="ItemTemplate" Value="{StaticResource DataTemplateForServerCards}"></Setter>
                        <Setter Property="Margin" Value="0"></Setter>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>






    <Grid Background="{DynamicResource PrimaryMidBrush}" Grid.IsSharedSizeScope="True">
        <Grid Margin="0 21 0 0" Background="{DynamicResource BackgroundBrush}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="*" MinHeight="300"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
            </Grid.RowDefinitions>

            <!-- Tag indicator: popup when any selected tag which is not in the `shown tag list` -->
            <Grid Grid.Row="0" MinHeight="40">
                <Grid.Style>
                    <Style TargetType="Grid">
                        <Setter Property="VerticalAlignment" Value="Top"></Setter>
                        <Setter Property="Visibility" Value="Collapsed"></Setter>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsTagFiltersShown}" Value="True">
                                <Setter Property="Visibility" Value="Visible"></Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Grid.Style>

                <ItemsControl VerticalAlignment="Center" HorizontalAlignment="Center" 
                              Margin="0 10 0 0"
                              ItemsSource="{Binding TagFilters}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate DataType="model:TagFilter">
                            <Border Margin="3" Padding="5"
                                    Background="{DynamicResource AccentMidBrush}" 
                                    CornerRadius="5" 
                                    VerticalAlignment="Center"
                                    ToolTip="{Binding TagName}"
                                    Tag="{Binding DataContext.TagsPanelViewModel, RelativeSource={RelativeSource AncestorType=serverList:ServerListPageView}}"
                                    >
                                <Border.ContextMenu>
                                    <ContextMenu>
                                        <MenuItem Header="{DynamicResource Unpin}" 
                                                  Visibility="{Binding IsPinned, Converter={StaticResource ConverterBool2Visible}}"
                                                  Command="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.Tag.CmdTagPin}" 
                                                  CommandParameter="{Binding}"/>
                                        <MenuItem Header="{DynamicResource Pin}" 
                                                  Visibility="{Binding IsPinned, Converter={StaticResource ConverterBool2VisibleInv}}"
                                                  Command="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.Tag.CmdTagPin}" 
                                                  CommandParameter="{Binding}"/>
                                        <MenuItem Header="{DynamicResource Rename}" 
                                                  Command="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.Tag.CmdTagRename}" 
                                                  CommandParameter="{Binding}"/>
                                        <MenuItem Header="{DynamicResource Connect}" 
                                                  Command="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.Tag.CmdTagConnect}" 
                                                  CommandParameter="{Binding}"/>
                                        <!--<MenuItem Header="{DynamicResource 'Connect (New window)'}" 
                                                  Command="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.Tag.CmdTagConnectToNewTab}" 
                                                  CommandParameter="{Binding}"/>-->
                                        <MenuItem Header="{DynamicResource 'Create desktop shortcut'}" 
                                                  Command="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.Tag.CmdCreateDesktopShortcut}" 
                                                  CommandParameter="{Binding}"/>
                                        <MenuItem Header="{DynamicResource Delete}" 
                                                  Command="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.Tag.CmdTagDelete}" 
                                                  CommandParameter="{Binding}"/>
                                    </ContextMenu>
                                </Border.ContextMenu>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding TagName}" 
                                               Foreground="{DynamicResource AccentTextBrush}" 
                                               Margin="0 0 3 0">
                                        <TextBlock.Style>
                                            <Style TargetType="TextBlock" BasedOn="{StaticResource TextBlockBase}">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding IsExcluded}" Value="True">
                                                        <Setter Property="TextDecorations">
                                                            <Setter.Value>
                                                                <TextDecorationCollection>
                                                                    <TextDecoration Location="Strikethrough">
                                                                        <TextDecoration.Pen>
                                                                            <Pen Brush="{DynamicResource PrimaryMidBrush}" Thickness="3"></Pen>
                                                                        </TextDecoration.Pen>
                                                                    </TextDecoration>
                                                                </TextDecorationCollection>
                                                            </Setter.Value>
                                                        </Setter>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </TextBlock.Style>
                                    </TextBlock>
                                    <Button Width="10" 
                                            Height="10" 
                                            Tag="{Binding TagName}"
                                            Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=serverList:ServerListPageView}, Path=DataContext.CmdTagRemove}"
                                            CommandParameter="{Binding TagName}"
                                            Style="{StaticResource ButtonBarAccentStyle}"
                                            attachProperty:VisionElement.Opacity="0.5"
                                            attachProperty:VisionElement.OpacityAccent="0.9">
                                        <Grid Height="10" Width="8">
                                            <Path Data="F1 M 47.910156 -44.000000 L 87.183594 -4.683594 L 83.316406 -0.816406 L 44.000000 -40.089844 L 4.683594 -0.816406 L 0.816406 -4.683594 L 40.089844 -44.000000 L 0.816406 -83.316406 L 4.683594 -87.183594 L 44.000000 -47.910156 L 83.316406 -87.183594 L 87.183594 -83.316406 Z "
                                                  Stroke="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType=Button}}"
                                                  Fill="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType=Button}}"
                                                  StrokeThickness="2" Stretch="Uniform" />
                                        </Grid>
                                    </Button>
                                </StackPanel>
                            </Border>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </Grid>


            <!-- server list-->
            <Grid Grid.Row="1">

                <Grid Name="GridHeader" Height="{StaticResource ServerItemHeight}" VerticalAlignment="Top" ZIndex="999">
                    <Grid.Style>
                        <Style TargetType="Grid">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsAddToolTipShow}" Value="True">
                                    <Setter Property="Visibility" Value="Collapsed"></Setter>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding ListPageIsCardView}" Value="True">
                                    <Setter Property="Visibility" Value="Collapsed"></Setter>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Grid.Style>
                    <Grid>
                        <Grid.Margin>
                            <Thickness Right="{StaticResource ScrollBarWidthMouseOver}"></Thickness>
                        </Grid.Margin>
                        <Border Background="{DynamicResource BackgroundBrush}">
                            <Border.Margin>
                                <Thickness Right="{StaticResource ScrollBarWidthMouseOver}"></Thickness>
                            </Border.Margin>
                        </Border>
                    </Grid>
                    <Grid VerticalAlignment="Center">
                        <Grid.Margin>
                            <Thickness Right="{StaticResource ScrollBarWidthMouseOver}"></Thickness>
                        </Grid.Margin>
                        <Grid.Resources>
                            <Style TargetType="Path" x:Key="HeaderPathStyle">
                                <Setter Property="Visibility" Value="Hidden" />
                                <Setter Property="StrokeThickness" Value="1" />
                                <Setter Property="Width" Value="20" />
                                <Setter Property="HorizontalAlignment" Value="Center" />
                                <Setter Property="Margin" Value="5,0,5,0" />
                                <Setter Property="SnapsToDevicePixels" Value="True" />
                            </Style>
                        </Grid.Resources>

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="Selector"></ColumnDefinition>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="Protocol" MinWidth="100"></ColumnDefinition>
                            <ColumnDefinition Width="40" SharedSizeGroup="Span"></ColumnDefinition>
                            <ColumnDefinition Width="300" SharedSizeGroup="Name"></ColumnDefinition>
                            <ColumnDefinition Width="200" SharedSizeGroup="Tags"></ColumnDefinition>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="BriefNote" MinWidth="50"></ColumnDefinition>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="Address"></ColumnDefinition>
                        </Grid.ColumnDefinitions>

                        <CheckBox Margin="11 0" Width="20" Height="20" HorizontalAlignment="Left" 
                                          IsChecked="{Binding IsSelectedAll, Mode=TwoWay}"
                                          x:Name="CheckBoxSelectedAll" 
                                          Click="ItemsCheckBox_OnClick"
                                          >
                        </CheckBox>

                        <!--protocol name-->
                        <Button Grid.Column="1" HorizontalContentAlignment="Left" Style="{StaticResource ButtonBarPrimaryStyle}"
                                Margin="0 0 10 0"
                                attachProperty:VisionElement.BorderCornerRadius="{StaticResource DefaultCornerRadius}"
                                Background="{DynamicResource BackgroundBrush}"
                                Foreground="{DynamicResource BackgroundTextBrush}"
                                Command="{Binding CmdReOrder}" CommandParameter="{x:Static locality:EnumServerOrderBy.ProtocolAsc}">
                            <Grid>
                                <Path Data="M 7,3 L 13,3 L 10,0 L 7,3" 
                                      Fill="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Foreground}"
                                      Style="{StaticResource HeaderPathStyle}"
                                      Visibility="{Binding ServerOrderBy, Converter={StaticResource ConverterEqual2Visible}, ConverterParameter={x:Static locality:EnumServerOrderBy.ProtocolAsc}}"
                                      >
                                </Path>
                                <Path Data="M 7,0 L 10,3 L 13,0 L 7,0" 
                                      Fill="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Foreground}"
                                      Style="{StaticResource HeaderPathStyle}"
                                      Visibility="{Binding ServerOrderBy, Converter={StaticResource ConverterEqual2Visible}, ConverterParameter={x:Static locality:EnumServerOrderBy.ProtocolDesc}}"
                                      >
                                </Path>
                                <TextBlock Style="{StaticResource TextBlockBase}" Margin="5" HorizontalAlignment="Left" Text="{DynamicResource Protocol}" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Foreground}"></TextBlock>
                            </Grid>
                        </Button>

                        <!--display name-->
                        <Button Grid.Column="3" HorizontalContentAlignment="Left" Style="{StaticResource ButtonBarPrimaryStyle}"
                                Margin="0 0 10 0"
                                attachProperty:VisionElement.BorderCornerRadius="{StaticResource DefaultCornerRadius}"
                                Background="{DynamicResource BackgroundBrush}"
                                Foreground="{DynamicResource BackgroundTextBrush}"
                                Command="{Binding CmdReOrder}" CommandParameter="{x:Static locality:EnumServerOrderBy.NameAsc}">
                            <Grid>
                                <Path Data="M 7,3 L 13,3 L 10,0 L 7,3" 
                                      Fill="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Foreground}"
                                      Style="{StaticResource HeaderPathStyle}"
                                      Visibility="{Binding ServerOrderBy, 
                                                    Converter={StaticResource ConverterEqual2Visible}, 
                                                    ConverterParameter={x:Static locality:EnumServerOrderBy.NameAsc}}"
                                      >
                                </Path>
                                <Path Data="M 7,0 L 10,3 L 13,0 L 7,0" 
                                      Fill="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Foreground}"
                                      Style="{StaticResource HeaderPathStyle}"
                                      Visibility="{Binding ServerOrderBy, Converter={StaticResource ConverterEqual2Visible}, ConverterParameter={x:Static locality:EnumServerOrderBy.NameDesc}}">
                                </Path>
                                <TextBlock Margin="5" HorizontalAlignment="Left" Text="{DynamicResource Name}" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Foreground}"></TextBlock>
                            </Grid>
                        </Button>

                        <!--brief note -->
                        <Grid Grid.Column="5" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="0 0 10 0">
                            <TextBlock Text="{DynamicResource Note}" 
                                       Style="{StaticResource TextBlockBase}"
                                       Margin="25 0 0 0" 
                                       Visibility="{Binding BriefNoteVisibility}" 
                                       Foreground="{DynamicResource BackgroundTextBrush}"
                                       VerticalAlignment="Center"></TextBlock>
                            <Grid HorizontalAlignment="Left" Margin="5 0 0 0">
                                <Button Width="20" Height="20"
                                        Style="{StaticResource ButtonBarPrimaryStyle}"
                                        Background="Transparent"
                                        attachProperty:VisionElement.BackgroundAccent="Transparent"
                                        attachProperty:VisionElement.BackgroundOnMouseDown="Transparent"
                                        HorizontalAlignment="Right"
                                        Visibility="{Binding BriefNoteVisibility}"
                                        Foreground="{DynamicResource BackgroundTextBrush}"
                                        attachProperty:VisionElement.ForegroundAccent="{DynamicResource BackgroundTextBrush}"
                                        attachProperty:VisionElement.ForegroundOnMouseDown="{DynamicResource BackgroundTextBrush}"
                                        attachProperty:VisionElement.Opacity="0.5"
                                        attachProperty:VisionElement.OpacityAccent="0.9"
                                        Command="{Binding CmdHideNoteField}" >
                                    <Grid Width="18">
                                        <Path Data="M989.866667 234.666667h-490.666667c-17.066667 0-34.133333-21.333333-34.133333-42.666667 0-25.6 12.8-42.666667 34.133333-42.666667h490.666667c17.066667 0 34.133333 17.066667 34.133333 42.666667 0 21.333333-12.8 42.666667-34.133333 42.666667z m-473.6 128h465.066666c25.6 0 46.933333 21.333333 46.933334 42.666666 0 25.6-21.333333 42.666667-46.933334 42.666667H516.266667c-25.6 0-46.933333-17.066667-46.933334-42.666667s21.333333-42.666667 46.933334-42.666666z m0 298.666666c-25.6 0-46.933333-21.333333-46.933334-42.666666 0-25.6 21.333333-42.666667 46.933334-42.666667h465.066666c25.6 0 46.933333 17.066667 46.933334 42.666667s-21.333333 42.666667-46.933334 42.666666H516.266667z m4.266666 128h452.266667c29.866667 0 51.2 17.066667 51.2 42.666667s-21.333333 42.666667-51.2 42.666667h-452.266667c-29.866667 0-51.2-17.066667-51.2-42.666667s21.333333-42.666667 51.2-42.666667z m-192 25.6c-17.066667 17.066667-46.933333 17.066667-64 0l-251.733333-273.066666c-17.066667-17.066667-17.066667-51.2 0-68.266667l251.733333-273.066667c17.066667-17.066667 46.933333-17.066667 64 0s17.066667 51.2 0 68.266667l-221.866666 238.933333 221.866666 238.933334c17.066667 21.333333 17.066667 51.2 0 68.266666z"
                                                  Stroke="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType=Button}}"
                                                  Fill="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType=Button}}"
                                                  StrokeThickness="0" Stretch="Uniform" />
                                    </Grid>
                                </Button>
                                <Button Width="20" Height="20" Margin="5 0 0 0"
                                        ToolTip="{DynamicResource Note}"
                                        Background="Transparent"
                                        attachProperty:VisionElement.BackgroundAccent="Transparent"
                                        attachProperty:VisionElement.BackgroundOnMouseDown="Transparent"
                                        HorizontalAlignment="Right"
                                        Foreground="{DynamicResource BackgroundTextBrush}"
                                        attachProperty:VisionElement.ForegroundAccent="{DynamicResource BackgroundTextBrush}"
                                        attachProperty:VisionElement.ForegroundOnMouseDown="{DynamicResource BackgroundTextBrush}"
                                        attachProperty:VisionElement.Opacity="0.5"
                                        attachProperty:VisionElement.OpacityAccent="0.9"
                                        Command="{Binding CmdShowNoteField}"
                                        Style="{StaticResource ButtonBarPrimaryStyle}"
                                        Visibility="{Binding BriefNoteVisibility, 
                                                    Converter={StaticResource ConverterEqual2Collapsed}, 
                                                    ConverterParameter={x:Static Visibility.Visible}}"
                                        >
                                    <Grid Width="18">
                                        <Path Data="M8.533333 192c0-25.6 17.066667-42.666667 34.133334-42.666667h490.666666c21.333333 0 34.133333 17.066667 34.133334 42.666667 0 21.333333-17.066667 42.666667-34.133334 42.666667h-490.666666c-21.333333 0-34.133333-21.333333-34.133334-42.666667z m550.4 213.333333c0 25.6-21.333333 42.666667-46.933333 42.666667h-465.066667c-25.6 0-46.933333-17.066667-46.933333-42.666667 0-21.333333 21.333333-42.666667 46.933333-42.666666h465.066667c25.6 0 46.933333 17.066667 46.933333 42.666666z m-507.733333 256c-25.6 0-46.933333-17.066667-46.933333-42.666666s21.333333-42.666667 46.933333-42.666667h465.066667c25.6 0 46.933333 17.066667 46.933333 42.666667 0 21.333333-21.333333 42.666667-46.933333 42.666666h-465.066667z m507.733333 170.666667c0 25.6-21.333333 42.666667-51.2 42.666667h-452.266666c-29.866667 0-51.2-17.066667-51.2-42.666667s21.333333-42.666667 51.2-42.666667h452.266666c29.866667 0 51.2 17.066667 51.2 42.666667z m140.8-85.333333l221.866667-238.933334-221.866667-238.933333c-17.066667-17.066667-17.066667-51.2 0-68.266667 17.066667-17.066667 46.933333-17.066667 64 0l251.733334 273.066667c17.066667 17.066667 17.066667 51.2 0 68.266667l-251.733334 273.066666c-17.066667 17.066667-46.933333 17.066667-64 0-17.066667-17.066667-17.066667-46.933333 0-68.266666z"
                                                  Stroke="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType=Button}}"
                                                  Fill="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType=Button}}"
                                                  StrokeThickness="0" Stretch="Uniform" />
                                    </Grid>
                                </Button>
                            </Grid>
                        </Grid>

                        <!--address-->
                        <Button Grid.Column="6" HorizontalContentAlignment="Left" Style="{StaticResource ButtonBarPrimaryStyle}"
                                Margin="0 0 10 0"
                                attachProperty:VisionElement.BorderCornerRadius="{StaticResource DefaultCornerRadius}"
                                Background="{DynamicResource BackgroundBrush}"
                                Foreground="{DynamicResource BackgroundTextBrush}"
                                Command="{Binding CmdReOrder}" CommandParameter="{x:Static locality:EnumServerOrderBy.AddressAsc}">
                            <Grid>
                                <Path Data="M 7,3 L 13,3 L 10,0 L 7,3" 
                                      Fill="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Foreground}"
                                      Style="{StaticResource HeaderPathStyle}"
                                      Visibility="{Binding ServerOrderBy, 
                                                    Converter={StaticResource ConverterEqual2Visible}, 
                                                    ConverterParameter={x:Static locality:EnumServerOrderBy.AddressAsc}}"
                                >
                                </Path>
                                <Path Data="M 7,0 L 10,3 L 13,0 L 7,0" 
                                      Fill="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Foreground}"
                                      Style="{StaticResource HeaderPathStyle}"
                                      Visibility="{Binding ServerOrderBy, 
                                                    Converter={StaticResource ConverterEqual2Visible}, 
                                                    ConverterParameter={x:Static locality:EnumServerOrderBy.AddressDesc}}"
                                >
                                </Path>
                                <TextBlock Margin="5" HorizontalAlignment="Left" 
                                           Style="{StaticResource TextBlockBase}"
                                           Text="{DynamicResource Target}" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Foreground}"></TextBlock>
                            </Grid>
                        </Button>
                    </Grid>
                </Grid>

                <ListBox Name="LvServerCards"
                         HorizontalContentAlignment="Stretch"
                         SelectedItem="{Binding SelectedServerViewModelListItem}"
                         ItemsSource="{Binding Source={StaticResource ServerListItemSource}}"
                         BorderThickness="0" Background="Transparent"
                         ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                         VirtualizingPanel.IsVirtualizing="True"
                         VirtualizingPanel.IsVirtualizingWhenGrouping="True"
                         VirtualizingPanel.ScrollUnit="Pixel"
                         Style="{StaticResource ServerListStyle}">

                    <ListBox.GroupStyle>
                        <GroupStyle>
                            <GroupStyle.ContainerStyle>
                                <Style TargetType="{x:Type GroupItem}">
                                    <Setter Property="AllowDrop" Value="true"/>
                                    <!--drop end event-->
                                    <EventSetter Event="Drop" Handler="ServerList_OnDrop"/>
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="{x:Type GroupItem}">
                                                <Grid>
                                                    <Expander IsExpanded="{Binding Items[0].GroupedIsExpanded}"
                                                              Background="{DynamicResource BackgroundBrush}" 
                                                              Foreground="{DynamicResource BackgroundTextBrush}" 
                                                              Style="{StaticResource ExpanderWithAnEye}"
                                                              BorderThickness="0">
                                                        <Expander.Header>
                                                            <StackPanel Orientation="Horizontal" AllowDrop="True">
                                                                <CheckBox Margin="6 0 0 0" Width="20" Height="20" HorizontalAlignment="Left"
                                                                          x:Name="HeaderCheckBox" 
                                                                          Click="ItemsCheckBox_OnClick"
                                                                >
                                                                </CheckBox>


                                                                <StackPanel Background="Transparent" 
                                                                            Orientation="Horizontal">
                                                                    <!--drag this element to sort groups-->
                                                                    <Grid Background="Transparent"
                                                                          Cursor="SizeNS"
                                                                          ToolTip="Drag to reorder groups"
                                                                          PreviewMouseDown="ServerList_OnPreviewMouseDown"
                                                                          PreviewMouseMove="ServerList_PreviewMouseMoveEvent">
                                                                        <Grid.Style>
                                                                            <Style TargetType="Grid">
                                                                                <Setter Property="Opacity" Value="0.2"></Setter>
                                                                                <Style.Triggers>
                                                                                    <Trigger Property="IsMouseOver" Value="True">
                                                                                        <Setter Property="Opacity" Value="1"></Setter>
                                                                                    </Trigger>
                                                                                </Style.Triggers>
                                                                            </Style>
                                                                        </Grid.Style>
                                                                        <Path Fill="{DynamicResource PrimaryTextBrush}"
                                                                              Width="15" Height="15"
                                                                              Stretch="Uniform"
                                                                              Data="M108.208681 670.888449c20.874205-16.374376 50.998058-12.87451 67.372434 7.999695l124.495258 158.368968V48.03717c0-26.498991 21.499181-47.998172 47.998172-47.998171S396.072717 21.53818 396.072717 48.03717v927.964658c0 20.499219-12.999505 38.623529-32.373767 45.373272-4.99981 1.749933-10.374605 2.6249-15.624405 2.6249-14.499448 0-28.498915-6.499752-37.748562-18.3743L100.08399 738.260883C83.709614 717.511673 87.334476 687.262825 108.208681 670.888449zM634.063653 2.663899c19.249267-6.749743 40.748448-0.374986 53.372967 15.7494l210.241993 267.364817c16.374376 20.74921 12.749514 50.998058-8.12469 67.372434-20.74921 16.374376-50.998058 12.87451-67.372434-7.999695l-124.495259-158.368969v789.219942c0 26.498991-21.499181 47.998172-47.998172 47.998172s-47.998172-21.499181-47.998172-47.998172V48.03717c0.124995-20.374224 13.1245-38.623529 32.373767-45.373271z m0 0"></Path>
                                                                    </Grid>

                                                                    <TextBlock FontWeight="Bold" 
                                                                               Style="{StaticResource TextBlockBase}"
                                                                               FontSize="16"
                                                                               Text="{Binding Path=Name}" 
                                                                               Margin="0,0,0,0"/>


                                                                    <!--Show database status-->
                                                                    <Button Margin="10 0 0 0"
                                                                            x:Name="ButtonDbStatus"
                                                                            Background="Transparent"
                                                                            attachProperty:VisionElement.BackgroundAccent="Transparent"
                                                                            attachProperty:VisionElement.BackgroundOnMouseDown="Transparent"
                                                                            Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=serverList:ServerListPageView}, Path=DataContext.CmdRefreshDataSource}"
                                                                            CommandParameter="{Binding Name}"
                                                                            ToolTip="{Binding Name.StatusInfo}">
                                                                        <Button.Style>  
                                                                            <Style TargetType="Button" BasedOn="{StaticResource ButtonBarAccentStyle}">
                                                                                <Setter Property="Content">
                                                                                    <Setter.Value>
                                                                                        <Path Height="20" Width="20" 
                                                                                                UseLayoutRounding="True" Stretch="Uniform">
                                                                                            <Path.Style>
                                                                                                <Style TargetType="Path">
                                                                                                    <Setter Property="Data" Value="{StaticResource GeometryCloudDisconnected}"></Setter>
                                                                                                    <Setter Property="Fill" Value="Red"></Setter>
                                                                                                    <Style.Triggers>
                                                                                                        <MultiDataTrigger>
                                                                                                            <MultiDataTrigger.Conditions>
                                                                                                                <Condition Binding="{Binding Name.Status}" Value="{x:Static dao:EnumDatabaseStatus.OK}"/>
                                                                                                                <Condition Binding="{Binding Name.IsWritable}" Value="True"/>
                                                                                                            </MultiDataTrigger.Conditions>
                                                                                                            <MultiDataTrigger.Setters>
                                                                                                                <Setter Property="Data" Value="{StaticResource GeometryCloudConnected}"></Setter>
                                                                                                                <Setter Property="Opacity" Value="0.2"></Setter>
                                                                                                                <Setter Property="Fill" Value="Green"></Setter>
                                                                                                            </MultiDataTrigger.Setters>
                                                                                                        </MultiDataTrigger>
                                                                                                        <MultiDataTrigger>
                                                                                                            <MultiDataTrigger.Conditions>
                                                                                                                <Condition Binding="{Binding Name.Status}" Value="{x:Static dao:EnumDatabaseStatus.OK}"/>
                                                                                                                <Condition Binding="{Binding Name.IsWritable}" Value="False"/>
                                                                                                            </MultiDataTrigger.Conditions>
                                                                                                            <MultiDataTrigger.Setters>
                                                                                                                <Setter Property="Data" Value="{StaticResource GeometryCloudConnectedReadonly}"></Setter>
                                                                                                                <Setter Property="Opacity" Value="0.2"></Setter>
                                                                                                                <Setter Property="Fill" Value="Green"></Setter>
                                                                                                            </MultiDataTrigger.Setters>
                                                                                                        </MultiDataTrigger>
                                                                                                    </Style.Triggers>
                                                                                                </Style>
                                                                                            </Path.Style>
                                                                                        </Path>
                                                                                    </Setter.Value>
                                                                                </Setter>
                                                                                <Style.Triggers>
                                                                                    <!--Show reconnect button when hover-->
                                                                                    <Trigger Property="IsMouseOver" Value="True">
                                                                                        <Setter Property="Content">
                                                                                            <Setter.Value>
                                                                                                <Grid Height="20" Width="20" >
                                                                                                    <Path Height="16" Width="16" UseLayoutRounding="True" Stretch="Uniform">
                                                                                                        <Path.Style>
                                                                                                            <Style TargetType="Path">
                                                                                                                <Setter Property="Data" Value="{StaticResource GeometryRefresh}"></Setter>
                                                                                                                <Setter Property="Fill" Value="{DynamicResource PrimaryTextBrush}"></Setter>
                                                                                                            </Style>
                                                                                                        </Path.Style>
                                                                                                    </Path>
                                                                                                </Grid>
                                                                                            </Setter.Value>
                                                                                        </Setter>
                                                                                    </Trigger>
                                                                                </Style.Triggers>
                                                                            </Style>
                                                                        </Button.Style>
                                                                    </Button>


                                                                    <Button Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=serverList:ServerListPageView}, Path=DataContext.CmdAdd}"
                                                                            CommandParameter="{Binding Name}"
                                                                            IsEnabled="{Binding Name.IsWritable}"
                                                                            Visibility="{Binding Name.Status, Converter={StaticResource ConverterEqual2Visible}, ConverterParameter={x:Static dao:EnumDatabaseStatus.OK}}"
                                                                            Background="Transparent"
                                                                            Margin="5 0 0 0"
                                                                            attachProperty:VisionElement.BackgroundAccent="Transparent"
                                                                            attachProperty:VisionElement.BackgroundOnMouseDown="Transparent"
                                                                            Style="{StaticResource ButtonBarAccentStyle}">
                                                                        <Grid Height="12" Width="12" >
                                                                            <Path Data="{StaticResource GeometryCross}" 
                                                                                  Stretch="Uniform" Name="Path"
                                                                                  Height="12" Width="12" 
                                                                                  Fill="{DynamicResource PrimaryTextBrush}">
                                                                                <Path.Style>
                                                                                    <Style TargetType="Path">
                                                                                        <Setter Property="Opacity" Value="0.5"></Setter>
                                                                                        <Style.Triggers>
                                                                                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=IsMouseOver}" Value="True">
                                                                                                <Setter Property="Opacity" Value="1"></Setter>
                                                                                            </DataTrigger>
                                                                                        </Style.Triggers>
                                                                                    </Style>
                                                                                </Path.Style>
                                                                            </Path>
                                                                        </Grid>
                                                                    </Button>


                                                                    <!--Show reconnect info if lost connect-->
                                                                    <TextBlock FontSize="12" Margin="5 0 0 0" 
                                                                               Foreground="{DynamicResource PrimaryTextBrush}"
                                                                               Opacity="0.5"
                                                                               VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Name.ReconnectInfo}">
                                                                        <TextBlock.Style>
                                                                            <Style TargetType="TextBlock" BasedOn="{StaticResource TextBlockBase}">
                                                                                <Setter Property="Visibility" Value="Collapsed"></Setter>
                                                                                <Style.Triggers>
                                                                                    <DataTrigger Binding="{Binding Name.Status, Converter={StaticResource ConverterIsEqual2Static}, ConverterParameter={x:Static dao:EnumDatabaseStatus.OK}}" Value="False">
                                                                                        <Setter Property="Visibility" Value="Visible"></Setter>
                                                                                    </DataTrigger>
                                                                                    <DataTrigger Binding="{Binding ElementName=ButtonDbStatus, Path=IsMouseOver}" Value="True">
                                                                                        <Setter Property="Visibility" Value="Visible"></Setter>
                                                                                    </DataTrigger>
                                                                                </Style.Triggers>
                                                                            </Style>
                                                                        </TextBlock.Style>
                                                                    </TextBlock>

                                                                </StackPanel>
                                                            </StackPanel>
                                                        </Expander.Header>
                                                        <Expander.Content>
                                                            <ItemsPresenter />
                                                        </Expander.Content>
                                                    </Expander>

                                                </Grid>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </GroupStyle.ContainerStyle>
                        </GroupStyle>
                    </ListBox.GroupStyle>
                </ListBox>


                <!-- footer: show detail of a server -->
                <Grid Name="GridBottom" VerticalAlignment="Bottom" Height="30" Background="{DynamicResource PrimaryMidBrush}" IsHitTestVisible="False">
                    <Grid.Style>
                        <Style TargetType="Grid">
                            <Setter Property="Opacity" Value="0.9"></Setter>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding ElementName=LvServerCards, Path=SelectedItem}" Value="{x:Null}">
                                    <Setter Property="Opacity" Value="0"></Setter>
                                </DataTrigger>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Opacity" Value="0"></Setter>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </Grid.Style>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
                        <StackPanel.Resources>
                            <Style TargetType="TextBlock" BasedOn="{StaticResource TextBlockBase}">
                                <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"></Setter>
                                <Setter Property="Margin" Value="0 0 5 0"></Setter>
                            </Style>
                        </StackPanel.Resources>
                        <TextBlock Text="{Binding SelectedServerViewModelListItem.Server.DisplayName}" Style="{StaticResource TextBlockBase}"></TextBlock>
                        <TextBlock Text="{Binding SelectedServerViewModelListItem.Server.SubTitle}" Style="{StaticResource TextBlockBase}"></TextBlock>
                    </StackPanel>
                </Grid>
            </Grid>


            <!-- tooltip for how to add -->
            <Border Grid.Row="1" HorizontalAlignment="Right" Visibility="{Binding IsAddToolTipShow, Converter={StaticResource ConverterBool2Visible}}">
                <StackPanel>
                    <Path Fill="{DynamicResource BackgroundTextBrush}" 
                          Margin="25 10 30 5" Width="50" HorizontalAlignment="Right"
                          Stretch="UniformToFill" Data="M 70.3711 1.2207 L 63.1409 2.666 L 68.054 2.78 C 61.006 12.645 49.14 12.505 47 24 C 46.938 24.449 47.885 24.549 48 24 C 50.066 12.953 62.38 12.673 68.819 3.201 L 69 8 Z" />
                    <TextBlock Margin="0 0 10 0" Foreground="{DynamicResource BackgroundTextBrush}" FontSize="22" FontWeight="Bold" HorizontalAlignment="Right">Add new session</TextBlock>
                    <StackPanel Orientation="Horizontal" Margin="0 0 10 0" 
                                Visibility="{Binding LauncherSettingViewModel.LauncherEnabled, Converter={StaticResource ConverterBool2Visible}}"
                                HorizontalAlignment="Right">
                        <StackPanel.Resources>
                            <Style TargetType="TextBlock" BasedOn="{StaticResource TextBlockBase}">
                                <Setter Property="Foreground" Value="{DynamicResource BackgroundTextBrush}"></Setter>
                                <Setter Property="Margin" Value="5 0 0 0"></Setter>
                                <Setter Property="FontSize" Value="16"></Setter>
                            </Style>
                        </StackPanel.Resources>
                        <TextBlock Text="{Binding LauncherSettingViewModel.LauncherHotKeyStr}"></TextBlock>
                        <TextBlock Text=" to open the launcher"></TextBlock>
                    </StackPanel>
                </StackPanel>
            </Border>


            <Border Grid.Row="1" HorizontalAlignment="Left" MinHeight="100" MinWidth="100" 
                    Margin="10 0 0 0"
                    Visibility="{Binding IsAddToolTipShow, Converter={StaticResource ConverterBool2Visible}}">
                <StackPanel>
                    <Path Fill="{DynamicResource BackgroundTextBrush}" 
                          Margin="80 10 30 5" Width="60" HorizontalAlignment="Left"
                          Stretch="UniformToFill" Data="M 67 0 L 62 4 L 66.62 2.035 C 66 12 47 10 47 24 C 47 24 47 24 48 24 C 48 10 67 13 67.362 2.074 L 72 4 Z" />
                    <TextBlock Margin="0 0 10 0" 
                               Style="{StaticResource TextBlockBase}"
                               Foreground="{DynamicResource BackgroundTextBrush}" 
                               FontSize="24" FontWeight="Bold">Right click on a tag</TextBlock>
                    <TextBlock Margin="5 0 0 0"
                               Style="{StaticResource TextBlockBase}"
                               FontSize="22" Foreground="{DynamicResource BackgroundTextBrush}"  
                    >and pin it here to to enable grouping function.</TextBlock>
                </StackPanel>
            </Border>



            <!-- popup when any item is selected-->
            <Grid Grid.Row="2" Background="{DynamicResource PrimaryMidBrush}" Height="40">
                <Grid.Style>
                    <Style TargetType="Grid">
                        <Setter Property="Visibility" Value="Visible"></Setter>
                        <Setter Property="Margin" Value="0 0 0 -50"></Setter>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsAnySelected}" Value="True">
                                <Setter Property="Visibility" Value="Visible"></Setter>
                                <DataTrigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <ThicknessAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetProperty="Margin" AccelerationRatio="0.9">
                                                <SplineThicknessKeyFrame KeyTime="0:0:0.0" Value="0,0,0,-50" />
                                                <SplineThicknessKeyFrame KeyTime="0:0:0.400" Value="0,0,0,0" />
                                            </ThicknessAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </DataTrigger.EnterActions>
                                <DataTrigger.ExitActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <ThicknessAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetProperty="Margin">
                                                <SplineThicknessKeyFrame KeyTime="0:0:0.0" Value="0,0,0,0" />
                                                <SplineThicknessKeyFrame KeyTime="0:0:0.200" Value="0,0,0,-50" />
                                            </ThicknessAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </DataTrigger.ExitActions>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Grid.Style>

                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                    <Button Height="30" MinWidth="80" Margin="5 0" Content="{DynamicResource Cancel}" Command="{Binding CmdCancelSelected}"></Button>
                    <TextBlock Style="{StaticResource TextBlockBase}" Text="{DynamicResource server_editor_multi_selected_count}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="{DynamicResource PrimaryTextBrush}"></TextBlock>
                    <TextBlock Style="{StaticResource TextBlockBase}" Text="{Binding SelectedCount}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="{DynamicResource PrimaryTextBrush}" Margin="5 0 0 0"></TextBlock>
                </StackPanel>

                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                    <Button Height="30" MinWidth="80" Margin="5 0 0 0" Content="{DynamicResource Connect}" Command="{Binding CmdConnectSelected}"></Button>
                    <Button Height="30" MinWidth="80" Margin="5 0 0 0" Content="{DynamicResource Edit}" Command="{Binding CmdMultiEditSelected}"></Button>
                    <Button Height="30" MinWidth="80" Margin="5 0 0 0" Content="{DynamicResource 'Create desktop shortcut'}" Command="{Binding CmdCreateDesktopShortcut}"></Button>
                    <Button Height="30" MinWidth="80" Margin="5 0 0 0" Content="{DynamicResource Delete}" Command="{Binding CmdDeleteSelected}"></Button>
                    <Button Height="30" MinWidth="80" Margin="5 0" Content="{DynamicResource Export}" Command="{Binding CmdExportSelectedToJson}"></Button>
                </StackPanel>
            </Grid>
        </Grid>







        <!-- tag list: the page to config which tag should be display. -->
        <ContentControl s:View.Model="{Binding TagListViewModel}"
                        Visibility="{Binding TagListViewModel, 
                                                    Converter={StaticResource ConverterEqual2Collapsed}, 
                                                    ConverterParameter={x:Null}}"
        >
        </ContentControl>






        <!-- tags list -->
        <Grid VerticalAlignment="Top">
            <Border BorderThickness="0 0 0 1" BorderBrush="{DynamicResource AccentMidBrush}" Background="{DynamicResource PrimaryTextBrush}" Height="20">
                <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="20">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <Button MinWidth="80"
                            Command="{Binding CmdShowMainTab}"
                            Content="{DynamicResource All}">
                        <Button.Style>
                            <Style TargetType="Button" BasedOn="{StaticResource ButtonBarPrimaryStyle}">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type Button}">
                                            <Grid>
                                                <Border Background="{TemplateBinding Background}"
                                                        SnapsToDevicePixels="true">
                                                </Border>
                                                <ContentPresenter HorizontalAlignment="Center"
                                                                  VerticalAlignment="Center"
                                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                                            </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                                <Style.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Background" Value="{DynamicResource AccentLightBrush}"></Setter>
                                        <Setter Property="Foreground" Value="{DynamicResource AccentTextBrush}" />
                                    </Trigger>
                                    <MultiDataTrigger>
                                        <MultiDataTrigger.Conditions>
                                            <Condition Binding="{Binding SelectedTabName}" Value=""/>
                                            <Condition Binding="{Binding TagListViewModel}" Value="{x:Null}"/>
                                        </MultiDataTrigger.Conditions>
                                        <MultiDataTrigger.Setters>
                                            <Setter Property="Background" Value="{DynamicResource AccentMidBrush}"></Setter>
                                            <Setter Property="Foreground" Value="{DynamicResource AccentTextBrush}" />
                                        </MultiDataTrigger.Setters>
                                    </MultiDataTrigger>
                                    <MultiDataTrigger>
                                        <MultiDataTrigger.Conditions>
                                            <Condition Binding="{Binding SelectedTabName}" Value="{x:Null}"/>
                                            <Condition Binding="{Binding TagListViewModel}" Value="{x:Null}"/>
                                        </MultiDataTrigger.Conditions>
                                        <MultiDataTrigger.Setters>
                                            <Setter Property="Background" Value="{DynamicResource AccentMidBrush}"></Setter>
                                            <Setter Property="Foreground" Value="{DynamicResource AccentTextBrush}" />
                                        </MultiDataTrigger.Setters>
                                    </MultiDataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Button.Style>
                    </Button>

                    <Button Grid.Column="1" MinWidth="80"
                            Command="{Binding CmdShowTagTab}"
                            BorderThickness="0" Content="{DynamicResource Tags}">
                        <Button.Style>
                            <Style TargetType="Button" BasedOn="{StaticResource ButtonBarPrimaryStyle}">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type Button}">
                                            <Grid>
                                                <Border Background="{TemplateBinding Background}"
                                                        SnapsToDevicePixels="true">
                                                </Border>
                                                <ContentPresenter HorizontalAlignment="Center"
                                                                  VerticalAlignment="Center"
                                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                                            </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                                <Setter Property="Background" Value="{DynamicResource AccentMidBrush}" />
                                <Setter Property="Foreground" Value="{DynamicResource AccentTextBrush}" />
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding TagListViewModel}" Value="{x:Null}">
                                        <Setter Property="Background" Value="{DynamicResource PrimaryMidBrush}" />
                                        <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" />
                                    </DataTrigger>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Background" Value="{DynamicResource AccentLightBrush}"></Setter>
                                        <Setter Property="Foreground" Value="{DynamicResource AccentTextBrush}" />
                                    </Trigger>
                                    <DataTrigger Binding="{Binding AppData.TagList.Count}" Value="0">
                                        <Setter Property="Visibility" Value="Collapsed"></Setter>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Button.Style>
                    </Button>

                    <ScrollViewer Grid.Column="2" HorizontalScrollBarVisibility="Auto" 
                                  Margin="10 0 0 0"
                                  Height="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType=Grid}, Path=Height}"
                                  controls1:ScrollViewerExtensions.IsHorizontalScrollOnWheelEnabled="true"
                                  attachProperty:VisionElement.ForegroundAccent="{DynamicResource PrimaryTextBrush}"
                                  attachProperty:VisionElement.BackgroundAccent="{DynamicResource PrimaryTextBrush}"
                                  Style="{StaticResource ScrollViewMiniStyle}">
                        <StackPanel Orientation="Horizontal">
                            <ItemsControl Name="ListBoxTags"
                                          ItemsSource="{Binding HeaderTags}"
                                          Background="{DynamicResource PrimaryMidBrush}"
                                          Height="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType=ScrollViewer}, Path=Height}"
                                          ScrollViewer.VerticalScrollBarVisibility="Hidden"
                                          ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                                          BorderThickness="0"
                                          Margin="0"
                                          Padding="0">
                                <ItemsControl.Style>
                                    <Style TargetType="ItemsControl">
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="ItemsControl">
                                                    <ItemsPresenter />
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </ItemsControl.Style>
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Horizontal"></StackPanel>
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>

                                <ItemsControl.ItemTemplate>
                                    <DataTemplate DataType="model:Tag">
                                        <Grid Tag="{Binding DataContext.TagsPanelViewModel, RelativeSource={RelativeSource AncestorType=serverList:ServerListPageView}}"
                                              AllowDrop="True"
                                              MouseMove="TagList_PreviewMouseMoveEvent"
                                              Drop="TagList_OnDrop"
                                              Background="Transparent"
                                            >
                                            <Grid.ContextMenu>
                                                <ContextMenu>
                                                    <MenuItem Header="{DynamicResource Unpin}" 
                                                              Visibility="{Binding IsPinned, Converter={StaticResource ConverterBool2Visible}}"
                                                              Command="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.Tag.CmdTagPin}" 
                                                              CommandParameter="{Binding}"/>
                                                    <MenuItem Header="{DynamicResource Rename}" 
                                                              Command="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.Tag.CmdTagRename}" 
                                                              CommandParameter="{Binding}"/>
                                                    <MenuItem Header="{DynamicResource Connect}" 
                                                              Command="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.Tag.CmdTagConnect}" 
                                                              CommandParameter="{Binding}"/>
                                                    <!--<MenuItem Header="{DynamicResource 'Connect (New window)'}" 
                                                              Command="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.Tag.CmdTagConnectToNewTab}" 
                                                              CommandParameter="{Binding}"/>-->
                                                    <MenuItem Header="{DynamicResource 'Create desktop shortcut'}" 
                                                              Command="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.Tag.CmdCreateDesktopShortcut}" 
                                                              CommandParameter="{Binding}"/>
                                                    <MenuItem Header="{DynamicResource Delete}" 
                                                              Command="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.Tag.CmdTagDelete}" 
                                                              CommandParameter="{Binding}"/>
                                                </ContextMenu>
                                            </Grid.ContextMenu>
                                            <Grid Visibility="{Binding IsPinned, Converter={StaticResource ConverterBool2Visible}}"
                                                  MouseLeftButtonDown="HeaderTag_OnClick"
                                                  Tag="{Binding Name}"
                                            >
                                                <Grid.Style>
                                                    <Style TargetType="Grid">
                                                        <Setter Property="MinWidth" Value="50" />
                                                        <Setter Property="Cursor" Value="Hand" />
                                                        <Setter Property="Background" Value="{DynamicResource PrimaryMidBrush}"></Setter>
                                                        <Style.Triggers>
                                                            <Trigger Property="IsMouseOver" Value="True">
                                                                <Setter Property="Background" Value="{DynamicResource AccentLightBrush}"></Setter>
                                                            </Trigger>
                                                            <DataTrigger Value="True">
                                                                <DataTrigger.Binding>
                                                                    <MultiBinding Converter="{StaticResource ConverterIsEqual}" >
                                                                        <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType=serverList:ServerListPageView}" Path="DataContext.SelectedTabName" Mode="OneWay"></Binding>
                                                                        <Binding Path="Name" Mode="OneWay"></Binding>
                                                                    </MultiBinding>
                                                                </DataTrigger.Binding>
                                                                <Setter Property="Background" Value="{DynamicResource AccentMidBrush}"></Setter>
                                                                <Setter Property="Cursor" Value="Arrow" />
                                                            </DataTrigger>
                                                            <DataTrigger Binding="{Binding IsPinned}" Value="False">
                                                                <Setter Property="Visibility" Value="Collapsed"></Setter>
                                                            </DataTrigger>
                                                        </Style.Triggers>
                                                    </Style>
                                                </Grid.Style>
                                                <TextBlock Text="{Binding Name}" 
                                                           Margin="8 0"
                                                           HorizontalAlignment="Center" VerticalAlignment="Center">
                                                    <TextBlock.Style>
                                                        <Style TargetType="TextBlock" BasedOn="{StaticResource TextBlockBase}">
                                                            <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"></Setter>
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Grid}, Path=IsMouseOver}" Value="True">
                                                                    <Setter Property="Foreground" Value="{DynamicResource AccentTextBrush}"></Setter>
                                                                </DataTrigger>
                                                                <DataTrigger Value="True">
                                                                    <DataTrigger.Binding>
                                                                        <MultiBinding Converter="{StaticResource ConverterIsEqual}" >
                                                                            <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType=serverList:ServerListPageView}" Path="DataContext.SelectedTabName" Mode="OneWay"></Binding>
                                                                            <Binding Path="Name" Mode="OneWay"></Binding>
                                                                        </MultiBinding>
                                                                    </DataTrigger.Binding>
                                                                    <Setter Property="Foreground" Value="{DynamicResource AccentTextBrush}"></Setter>
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </TextBlock.Style>
                                                </TextBlock>
                                            </Grid>
                                            <!--<TextBlock Text="{Binding Name}" Background="Red" Visibility="{Binding IsPinned, Converter={StaticResource ConverterBool2Visible}}"></TextBlock>-->
                                        </Grid>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </StackPanel>
                    </ScrollViewer>

                    <CheckBox Grid.Column="3"
                              Name="CbPopForInExport" 
                              Width="30" Height="20">
                        <CheckBox.Template>
                            <ControlTemplate>
                                <Border Name="BG" Background="{DynamicResource PrimaryMidBrush}">
                                    <Grid Margin="1" VerticalAlignment="Center">
                                        <Path Data="M 41.888 18.304 L 41.888 23.584 L 23.584 23.584 L 23.584 41.888 L 18.304 41.888 L 18.304 23.584 L 0 23.584 L 0 18.304 L 18.304 18.304 L 18.304 0 L 23.584 0 L 23.584 18.304 Z"
                                              Stretch="Uniform" Name="Path"
                                              Margin="2" Fill="{DynamicResource PrimaryTextBrush}"></Path>
                                    </Grid>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="CheckBox.IsMouseOver" Value="True">
                                        <Setter TargetName="BG" Property="Background" Value="{DynamicResource PrimaryLightBrush}"></Setter>
                                        <Setter TargetName="Path" Property="Margin" Value="1"></Setter>
                                        <Setter TargetName="Path" Property="Fill" Value="{DynamicResource PrimaryTextBrush}"></Setter>
                                    </Trigger>
                                    <Trigger Property="CheckBox.IsChecked" Value="True">
                                        <Setter TargetName="BG" Property="Background" Value="{DynamicResource PrimaryDarkBrush}"></Setter>
                                        <Setter TargetName="Path" Property="Fill" Value="{DynamicResource PrimaryTextBrush}"></Setter>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </CheckBox.Template>
                    </CheckBox>

                    <Popup Grid.Column="2"  Name="PopupMenuInExport"
                           IsOpen="{Binding ElementName=CbPopForInExport, Path=IsChecked}"
                           StaysOpen="False"
                           AllowsTransparency="True"
                           PlacementTarget="{Binding ElementName=CbPopForInExport}">
                        <Border CornerRadius="5" Background="{DynamicResource PrimaryDarkBrush}">
                            <StackPanel Orientation="Vertical">
                                <MenuItem Header="{DynamicResource Add}" Command="{Binding CmdAdd}">
                                    <MenuItem.Icon>
                                        <Path Data="{StaticResource GeometryCross}"
                                              Stretch="Uniform" Name="Path"
                                              Margin="2" Fill="{DynamicResource PrimaryTextBrush}"></Path>
                                    </MenuItem.Icon>
                                </MenuItem>
                                <Separator Style="{StaticResource SeparatorBaseStyle}"/>
                                <MenuItem Header="{DynamicResource import_from_json}" Command="{Binding CmdImportFromJson}">
                                    <MenuItem.Icon>
                                        <Path UseLayoutRounding="True" Data="{StaticResource GeometryCopy}" Fill="{DynamicResource PrimaryTextBrush}" Stretch="Uniform"/>
                                    </MenuItem.Icon>
                                </MenuItem>
                                <MenuItem Header="{DynamicResource import_from_mremoteng_csv}" Command="{Binding CmdImportFromCsv}"></MenuItem>
                                <MenuItem Header="{DynamicResource import_from_rdp_file}" Command="{Binding CmdImportFromRdp}"></MenuItem>
                                <MenuItem Header="{DynamicResource import_from_sqlite_db}" Command="{Binding CmdImportFromDatabase}"></MenuItem>
                            </StackPanel>
                        </Border>
                    </Popup>
                </Grid>
            </Border>
        </Grid>
    </Grid>
</UserControl>