<UserControl x:Class="NEIntelligentControl2.Views.MainWindow.TitleBar"
             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:local="clr-namespace:NEIntelligentControl2.Views.MainWindow"
             mc:Ignorable="d" 
             d:DesignHeight="68" d:DesignWidth="1920">
    <UserControl.Resources>
        <SolidColorBrush x:Key="TitleBackground" Color="#FF253887"/>
        <SolidColorBrush x:Key="TitleMouseOver" Color="#FF4D62BD"/>
        <SolidColorBrush x:Key="ListBox.Foreground" Color="WhiteSmoke"/>

        <Style x:Key="TitleGridStyle" TargetType="Grid">
            <Setter Property="Background" Value="{StaticResource TitleBackground}"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="{StaticResource TitleMouseOver}"/>
                </Trigger>
            </Style.Triggers>
        </Style>


        <Style x:Key="ListBoxStyleMain" TargetType="{x:Type ListBox}">
            <Setter Property="Foreground" Value="{StaticResource ListBox.Foreground}"/>
            <Setter Property="VerticalContentAlignment" Value="Stretch"/>
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBox}">
                        <Border x:Name="Bd" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="true">
                            <ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}">
                                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            </ScrollViewer>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">

                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsGrouping" Value="true"/>
                                    <Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <ItemsPanelTemplate x:Key="ItemsPanelTemplateMian">
            <VirtualizingStackPanel IsItemsHost="True" Orientation="Horizontal"/>
        </ItemsPanelTemplate>

        <Style x:Key="ListBoxItemStyleMain" TargetType="{x:Type ListBoxItem}">
            <Setter Property="SnapsToDevicePixels" Value="True"/>
            <Setter Property="Padding" Value="4,0"/>
            <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
            <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <Border x:Name="Bd" SnapsToDevicePixels="true" MinWidth="92" MaxWidth="94" VerticalAlignment="Stretch">
                            <Border.Background>
                                <ImageBrush ImageSource="pack://application:,,,/智动启停;component/Images/TitleBar/item_background.png"/>
                            </Border.Background>
                            <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,5"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Background" TargetName="Bd">
                                    <Setter.Value>
                                        <ImageBrush ImageSource="pack://application:,,,/智动启停;component/Images/TitleBar/item_background_selected.png"/>
                                    </Setter.Value>
                                </Setter>
                                <Setter Property="Foreground" Value="#FF2F31B0"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>


        <Style x:Key="PopupItemGrid" TargetType="Grid">
            <Setter Property="Height" Value="44"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="#FF646464"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <Grid SnapsToDevicePixels="True" Background="{StaticResource TitleBackground}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition Width="2.3*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>

        <Image Source="pack://application:,,,/智动启停;component/Images/TitleBar/background.png" HorizontalAlignment="Left" Margin="20,0,0,0"/>
        
        <ListBox Visibility="Collapsed" x:Name="_LBMain" Grid.Column="1" DisplayMemberPath="Name" Style="{StaticResource ListBoxStyleMain}" ItemsPanel="{StaticResource ItemsPanelTemplateMian}" ItemContainerStyle="{StaticResource ListBoxItemStyleMain}" Height="33" VerticalAlignment="Bottom" ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Hidden" SelectionChanged="_LBMain_SelectionChanged"/>

        <Grid Grid.Column="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid Width="117" Style="{StaticResource TitleGridStyle}" MouseLeftButtonUp="Grid_MouseLeftButtonUp" Tag="user" Visibility="Hidden">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="2*"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <TextBlock x:Name="_TBUser" Text="未登录" HorizontalAlignment="Right" VerticalAlignment="Center" Foreground="WhiteSmoke" FontSize="18"/>
                <Viewbox Width="27" Height="27" Grid.Column="1">
                    <Canvas Width="1024" Height="1024">
                        <Path Fill="WhiteSmoke" Data="M501.937582 545.097053c147.891962 0 268.231366-118.534055 268.223274-264.288929 0-145.746783-120.330301-264.28994-268.222263-264.28994-147.890951 0-268.221252 118.584625-268.221252 264.28994C233.71633 426.520519 354.046631 545.097053 501.937582 545.097053zM612.471463 570.546911 411.497184 570.546911c-186.760063 0-338.664249 149.569875-338.664249 333.472733l0 19.794109c0 96.139636 149.47278 96.139636 338.664249 96.139636l200.974278 0c181.747565 0 338.694591 0 338.694591-96.139636l0-19.794109C951.164031 720.158252 799.235571 570.546911 612.471463 570.546911z"/>
                    </Canvas>
                </Viewbox>
            </Grid>
            <Rectangle Grid.Column="1" Fill="WhiteSmoke" Width="2"/>
            <Grid Grid.Column="2" Width="68" Style="{StaticResource TitleGridStyle}" MouseLeftButtonUp="Grid_MouseLeftButtonUp" Tag="close">
                <Viewbox Width="27" Height="27">
                    <Canvas Width="1024" Height="1024">
                        <Path Fill="WhiteSmoke" Data="M464.621946 124.483152c0-26.264177 21.324678-47.589878 47.582715-47.589878 26.258037 0 47.662533 21.324678 47.662533 47.589878v299.552424c0 26.264177-21.404496 47.589878-47.662533 47.589878-26.258037 0-47.582715-21.324678-47.582715-47.589878v-299.552424z"/>
                        <Path Fill="WhiteSmoke" Data="M813.450656 822.458821c-166.205393 166.205393-436.678524 166.205393-602.936105-0.053212-166.205393-166.205393-166.205393-436.678524 0-602.883917 18.191314-18.191314 47.709605-18.191314 65.900919 0s18.191314 47.709605 0 65.900919c-129.868813 129.875976-129.868813 341.207126 0 471.082079 129.868813 129.868813 341.260337 129.922025 471.129151 0.053212 129.875976-129.875976 129.875976-341.319689 0-471.188502-18.191314-18.191314-18.191314-47.708582 0-65.90092 18.198477-18.191314 47.708582-18.191314 65.907059 0 166.250418 166.259628 166.250418 436.732759-0.001024 602.990341z"/>
                    </Canvas>
                </Viewbox>
            </Grid>
            <Popup x:Name="_PUser" Width="205">
                <Grid Background="#FF454545" MouseLeave="Grid_MouseLeave">
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid Style="{StaticResource PopupItemGrid}" MouseLeftButtonUp="Grid_MouseLeftButtonUp" Tag="useradd">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="2*"/>
                        </Grid.ColumnDefinitions>
                        <Image Width="32" Height="32" Source="pack://application:,,,/智动启停;component/Images/TitleBar/user_add.png"/>
                        <TextBlock Grid.Column="1" Text="用户添加" VerticalAlignment="Center" Foreground="WhiteSmoke" FontSize="15"/>
                    </Grid>
                    <Grid Grid.Row="1" Style="{StaticResource PopupItemGrid}" MouseLeftButtonUp="Grid_MouseLeftButtonUp" Tag="useredit">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="2*"/>
                        </Grid.ColumnDefinitions>

                        <Image Width="32" Height="32" Source="pack://application:,,,/智动启停;component/Images/TitleBar/user_edit.png"/>
                        <TextBlock Grid.Column="1" Text="用户编辑" VerticalAlignment="Center" Foreground="WhiteSmoke" FontSize="15"/>
                    </Grid>
                    <Grid Grid.Row="2" Style="{StaticResource PopupItemGrid}" MouseLeftButtonUp="Grid_MouseLeftButtonUp" Tag="logout">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="2*"/>
                        </Grid.ColumnDefinitions>

                        <Image Width="32" Height="32" Source="pack://application:,,,/智动启停;component/Images/TitleBar/user_logout.png"/>
                        <TextBlock Grid.Column="1" Text="注       销" VerticalAlignment="Center" Foreground="WhiteSmoke" FontSize="15"/>
                    </Grid>
                </Grid>
            </Popup>
        </Grid>
    </Grid>
</UserControl>
