<Window
    x:Class="BPASmartClient.DosingSystem.View.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:control="clr-namespace:BPASmartClient.CustomResource.UserControls;assembly=BPASmartClient.CustomResource"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:BPASmartClient.DosingSystem"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:pry="clr-namespace:BPASmartClient.CustomResource.UserControls;assembly=BPASmartClient.CustomResource"
    xmlns:vm="clr-namespace:BPASmartClient.DosingSystem.ViewModel"
    Title="MainWindow"
    Width="1300"
    Height="800"
    AllowsTransparency="True"
    Background="{x:Null}"
    Topmost="False"
    WindowStartupLocation="CenterScreen"
    WindowStyle="None"
    mc:Ignorable="d">

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/GenricStyle.xaml" />
                <ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/MyStyle.xaml" />

                <ResourceDictionary>
                    <!--#region ListBox样式-->
                    <Style x:Key="ListBoxItemStyle1" TargetType="{x:Type ListBoxItem}">
                        <Setter Property="OverridesDefaultStyle" Value="True" />
                        <Setter Property="SnapsToDevicePixels" Value="True" />
                        <Setter Property="BorderBrush" Value="{x:Null}" />
                        <Setter Property="Foreground" Value="White" />
                        <Setter Property="FontSize" Value="20" />
                        <Setter Property="HorizontalContentAlignment" Value="Center" />
                        <Setter Property="VerticalContentAlignment" Value="Center" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                    <Border x:Name="border" CornerRadius="8">
                                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                    <!--#endregion-->
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>

    <Window.DataContext>
        <vm:MainViewModel />
    </Window.DataContext>

    <Border x:Name="br" Style="{DynamicResource border主窗体背景}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="60" />
                <RowDefinition />
            </Grid.RowDefinitions>

            <!--  标题  -->
            <Grid Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="300" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Border
                    Grid.ColumnSpan="2"
                    Height="52"
                    VerticalAlignment="Top"
                    Style="{DynamicResource bordertop矩形}" />
                <Border Style="{DynamicResource bordertopL}" />
                <Image
                    Margin="20,0,0,0"
                    VerticalAlignment="Center"
                    Style="{DynamicResource imagetop_Title}" />
                <Grid Grid.Column="1">

                    <ListBox
                        x:Name="lstEnt"
                        Background="{x:Null}"
                        BorderBrush="{x:Null}"
                        BorderThickness="0"
                        ItemContainerStyle="{StaticResource ResourceKey=ListBoxItemStyle1}"
                        ItemsSource="{Binding Menus}">
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Horizontal" />
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <RadioButton
                                    Command="{Binding DataContext.TogglePag, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
                                    CommandParameter="{Binding CommandParameter}"
                                    Content="{Binding MenuName}"
                                    GroupName="all"
                                    Style="{StaticResource MenuRadioButtonStyle}" />
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </Grid>

                <StackPanel
                    Grid.Column="4"
                    Height="50"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Top"
                    Orientation="Horizontal">
                    <Border Style="{DynamicResource border竖线}" />

                    <Grid>

                        <ToggleButton
                            Name="tb"
                            Margin="5"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Cursor="Hand"
                            IsChecked="{Binding UserManagement}"
                            Style="{DynamicResource StatusBtnStyle网络连接状态}"
                            ToolTip="用户管理" />

                        <!--  当 StaysOpen 设置为 True 时 popup失去焦点的时候不会自动关闭  -->
                        <Popup
                            AllowsTransparency="True"
                            Focusable="False"
                            IsOpen="{Binding IsChecked, ElementName=tb}"
                            Placement="Bottom"
                            PlacementTarget="{Binding ElementName=tb}"
                            StaysOpen="False">
                            <Border Background="#081424" ClipToBounds="True">
                                <Grid Width="100" Margin="0">
                                    <StackPanel Width="{Binding RelativeSource={RelativeSource AncestorLevel=1, AncestorType=Grid}, Path=ActualWidth}">
                                        <Button
                                            Width="{Binding RelativeSource={RelativeSource AncestorLevel=1, AncestorType=Grid}, Path=ActualWidth}"
                                            Margin="0,5,0,1"
                                            HorizontalAlignment="Center"
                                            VerticalAlignment="Center"
                                            Command="{Binding PasswordChange}"
                                            Content="密码修改"
                                            Cursor="Hand" />
                                        <Button
                                            Width="{Binding RelativeSource={RelativeSource AncestorLevel=1, AncestorType=Grid}, Path=ActualWidth}"
                                            Margin="0,5,0,1"
                                            HorizontalAlignment="Center"
                                            VerticalAlignment="Center"
                                            Command="{Binding Login}"
                                            Content="登录账号"
                                            Cursor="Hand" />
                                        <Button
                                            Width="{Binding RelativeSource={RelativeSource AncestorLevel=1, AncestorType=Grid}, Path=ActualWidth}"
                                            Margin="0,5,0,1"
                                            HorizontalAlignment="Center"
                                            VerticalAlignment="Center"
                                            Command="{Binding ExitLogin}"
                                            Content="退出登录"
                                            Cursor="Hand" />
                                    </StackPanel>
                                </Grid>
                            </Border>
                        </Popup>
                    </Grid>


                    <Border Style="{DynamicResource border竖线}" />
                    <ToggleButton
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        Cursor="Hand"
                        DataContext="{Binding IsAlarm}"
                        Style="{DynamicResource StatusBtnStyle告警}"
                        ToolTip="告警消息" />
                    <Border Style="{DynamicResource border竖线}" />
                    <control:DateTimeUI Margin="10,0,10,0" VerticalAlignment="Center" />
                    <Border Style="{DynamicResource border竖线}" />
                    <Button
                        x:Name="ButClose"
                        Grid.Column="4"
                        Margin="10,0,20,0"
                        VerticalAlignment="Center"
                        Content="退出"
                        Cursor="Hand"
                        Style="{DynamicResource CommonBtn_返回}"
                        ToolTip="退出程序" />

                </StackPanel>
            </Grid>

            <!--  底部窗体  -->
            <Grid Grid.Row="1" Margin="10">
                <Grid.RowDefinitions>
                    <RowDefinition Height="45" />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <!--  顶部装饰  -->
                <Border
                    Grid.Row="0"
                    Grid.RowSpan="2"
                    Style="{DynamicResource border右下}" />

                <Border
                    Grid.Row="0"
                    Grid.RowSpan="2"
                    Style="{DynamicResource border左下}" />

                <Border
                    Grid.Row="0"
                    Grid.RowSpan="2"
                    Style="{DynamicResource border右上}" />

                <Border
                    Grid.Row="0"
                    Grid.RowSpan="2"
                    Style="{DynamicResource border左上}" />

                <Grid Margin="10">
                    <Border Width="600" Style="{DynamicResource borderFromTitle}" />

                    <StackPanel Orientation="Horizontal">
                        <CheckBox
                            Margin="5,0,5,0"
                            Content="开机启动"
                            IsChecked="{Binding AutoStart}" />
                    </StackPanel>

                    <TextBlock
                        x:Name="Title"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Top"
                        FontSize="16"
                        Foreground="#feffff"
                        Text="{Binding WindowTitleName}" />

                </Grid>

                <!--#region 底部窗体栏-->
                <ContentControl
                    x:Name="contentRegion"
                    Grid.Row="1"
                    Content="{Binding MyWindow}" />
                <!--#endregion-->
            </Grid>


        </Grid>
    </Border>
</Window>
