<UserControl x:Class="VIZ.Package.Module.MainConnView"
             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:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
             xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
             xmlns:dxdo="http://schemas.devexpress.com/winfx/2008/xaml/docking"
             xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
             xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
             xmlns:fcore="clr-namespace:VIZ.Framework.Core;assembly=VIZ.Framework.Core"
             xmlns:plugin="clr-namespace:VIZ.Package.Plugin;assembly=VIZ.Package.Plugin"
             xmlns:resource="clr-namespace:VIZ.Package.Module.Resource;assembly=VIZ.Package.Module.Resource"
             xmlns:local="clr-namespace:VIZ.Package.Module"
             d:DataContext="{d:DesignInstance Type=local:MainConnViewModel}" 
             mc:Ignorable="d"  x:Name="uc"
             d:DesignHeight="35" d:DesignWidth="800">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/VIZ.Framework.Common.Resource;component/Style/ListBox/ListBox_None.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>

            <fcore:Bool2BoolConverter x:Key="Bool2BoolConverter"></fcore:Bool2BoolConverter>

            <resource:ConnGroupStatus2BrushConverter x:Key="ConnGroupStatus2BrushConverter"
                                                     AllDisconnectionBrush="#FFFF5353"
                                                     AnyConnectionBrush="Yellow"
                                                     AllConnectionBrush="#FF92FF3D"></resource:ConnGroupStatus2BrushConverter>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid>
        <ListBox Style="{StaticResource ListBox_None}" Margin="10,0,0,0"
                 ItemsSource="{Binding Path=ItemsSrouce}"
                 ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                 ScrollViewer.VerticalScrollBarVisibility="Hidden">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"></StackPanel>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid Background="Transparent" x:Name="root">
                        <!-- 内容 -->
                        <StackPanel Orientation="Horizontal">
                            <Border Width="16" Height="16" VerticalAlignment="Center"
                                    Background="{Binding Path=Status,Converter={StaticResource ConnGroupStatus2BrushConverter}}">
                                <Border.OpacityMask>
                                    <ImageBrush ImageSource="/VIZ.Package.Module.Resource;component/Icons/preview_connection_32x32.png"></ImageBrush>
                                </Border.OpacityMask>
                            </Border>
                            <TextBlock Text="{Binding Path=Name}" Grid.Column="1" VerticalAlignment="Center" Margin="10,0,50,0" 
                                       MaxWidth="200"
                                       Foreground="{Binding Path=Status,Converter={StaticResource ConnGroupStatus2BrushConverter}}"
                                       TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"></TextBlock>
                        </StackPanel>

                        <!-- 弹出框 -->
                        <Popup AllowsTransparency="True"
                               PopupAnimation="Fade"
                               PlacementTarget="{Binding ElementName=root}"
                               Placement="Top"
                               Width="320"
                               MinHeight="200"
                               IsOpen="{Binding ElementName=root, Path=IsMouseOver, Mode=OneWay}">
                            <Border Background="#FF252526" BorderBrush="#FF4E4BDE" BorderThickness="1" Width="300">
                                <Grid Margin="20">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="40"></RowDefinition>
                                        <RowDefinition Height="*"></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="分组: " Foreground="#aaffffff"></TextBlock>
                                        <TextBlock Text="{Binding Path=Name}" Margin="10,0,10,0" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"></TextBlock>
                                    </StackPanel>

                                    <ListBox Style="{StaticResource ListBox_None}" ItemsSource="{Binding Path=Items}" Grid.Row="1">
                                        <ListBox.ItemTemplate>
                                            <DataTemplate>
                                                <StackPanel x:Name="innerRoot"
                                                            Orientation="Horizontal" Background="Transparent" VerticalAlignment="Center"
                                                            IsEnabled="{Binding Path=IsLoading,Converter={StaticResource Bool2BoolConverter}}"
                                                            TextBlock.Foreground="#FFFF5353"
                                                            TextBlock.FontSize="12" Height="24 "
                                                            Cursor="Hand">
                                                    <dxmvvm:Interaction.Behaviors>
                                                        <dxmvvm:EventToCommand Event="PreviewMouseLeftButtonDown" 
                                                                               CommandParameter="{Binding .}"
                                                                               Command="{Binding Path=DataContext.ItemClickCommand,ElementName=uc}"></dxmvvm:EventToCommand>
                                                    </dxmvvm:Interaction.Behaviors>
                                                    <TextBlock Text="{Binding Path=IP}" VerticalAlignment="Center"></TextBlock>
                                                    <TextBlock Text=":" Margin="3,0,3,0" VerticalAlignment="Center"></TextBlock>
                                                    <TextBlock Text="{Binding Path=Port}" VerticalAlignment="Center"></TextBlock>
                                                    <TextBlock Text="[" Margin="3,0,3,0" VerticalAlignment="Center"></TextBlock>
                                                    <TextBlock Text="{Binding Path=Remark}" VerticalAlignment="Center"></TextBlock>
                                                    <TextBlock Text="]" Margin="3,0,3,0" VerticalAlignment="Center"></TextBlock>
                                                </StackPanel>
                                                <DataTemplate.Triggers>
                                                    <DataTrigger Binding="{Binding Path=IsConnected}" Value="True">
                                                        <Setter Property="TextBlock.Foreground" TargetName="innerRoot" Value="#FF92FF3D"></Setter>
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding Path=IsEnabled}" Value="False">
                                                        <Setter Property="IsEnabled" Value="False"></Setter>
                                                        <Setter Property="Opacity" Value="0.4"></Setter>
                                                        <Setter Property="TextBlock.Foreground" TargetName="innerRoot" Value="White"></Setter>
                                                    </DataTrigger>
                                                </DataTemplate.Triggers>
                                            </DataTemplate>
                                        </ListBox.ItemTemplate>
                                    </ListBox>
                                </Grid>
                            </Border>
                        </Popup>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>

</UserControl>
