<UserControl
    x:Class="BPASmartClient.Control.DeviceMonitorView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:BPASmartClient.Control"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:vm="clr-namespace:BPASmartClient.ViewModel;assembly=BPASmartClient.ViewModel"
    d:DesignHeight="450"
    d:DesignWidth="800"
    mc:Ignorable="d">
    <UserControl.DataContext>
        <vm:DeviceMonitorViewModel />
    </UserControl.DataContext>

    <UserControl.Resources>

        <!--#region 静态资源-->
        <ImageBrush x:Key="leftImage" ImageSource="/BPASmartClient.CustomResource;component/Image/leftImage.png" />
        <ImageBrush x:Key="leftImageSub" ImageSource="/BPASmartClient.CustomResource;component/Image/leftImageSub.png" />
        <ImageBrush x:Key="topImage" ImageSource="/BPASmartClient.CustomResource;component/Image/topImage.png" />
        <!--#endregion-->

        <!--#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.Triggers>
                                        <Trigger Property="IsSelected" Value="True">
                                            <Setter TargetName="border" Property="Background">
                                                <Setter.Value>
                                                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                                        <GradientStop Offset="0.5" Color="#FF6B6B6B" />
                                                        <GradientStop Offset="0.5" Color="#FF535353" />
                                                        <GradientStop Offset="0.022" Color="#FF535353" />
                                                        <GradientStop Offset="0.991" Color="#FF555555" />
                                                    </LinearGradientBrush>
                                                </Setter.Value>
                                            </Setter>
                                        </Trigger>
                                    </ControlTemplate.Triggers>-->
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <!--#endregion-->

        <!--#region 下拉列表单选按钮样式-->
        <Style x:Key="RadioMiniButtonStyle" TargetType="{x:Type RadioButton}">
            <Setter Property="Margin" Value="5,10,1,0" />
            <Setter Property="Width" Value="160" />
            <Setter Property="Height" Value="30" />
            <Setter Property="FontSize" Value="14" />
            <Setter Property="FontFamily" Value="粗体" />
            <Setter Property="Foreground" Value="#DDD" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="HorizontalContentAlignment" Value="Center" />
            <Setter Property="BorderBrush" Value="Transparent" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="Background" Value="#DDD" />
            <Setter Property="HorizontalAlignment" Value="Right" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type RadioButton}">
                        <Grid
                            x:Name="templateRoot"
                            Background="Transparent"
                            SnapsToDevicePixels="True">
                            <Border x:Name="border2" />
                            <ContentPresenter
                                x:Name="contentPresenter"
                                Margin="{TemplateBinding Padding}"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                Content="{TemplateBinding Content}"
                                ContentStringFormat="{TemplateBinding ContentStringFormat}"
                                ContentTemplate="{TemplateBinding ContentTemplate}"
                                Focusable="False"
                                RecognizesAccessKey="True"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />

                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="HasContent" Value="True">
                                <Setter Property="FocusVisualStyle">
                                    <Setter.Value>
                                        <Style>
                                            <Setter Property="Control.Template">
                                                <Setter.Value>
                                                    <ControlTemplate>
                                                        <Rectangle
                                                            Margin="14,0,0,0"
                                                            SnapsToDevicePixels="True"
                                                            Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
                                                            StrokeDashArray="1 2"
                                                            StrokeThickness="1" />
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </Setter.Value>
                                </Setter>
                                <Setter Property="Padding" Value="4,-1,0,0" />
                            </Trigger>
                            <Trigger Property="IsChecked" Value="{x:Null}" />

                            <Trigger Property="IsChecked" Value="true">
                                <Setter Property="Foreground" Value="White" />
                                <Setter TargetName="border2" Property="Background" Value="{StaticResource ResourceKey=leftImageSub}" />
                            </Trigger>

                            <Trigger Property="IsChecked" Value="false">
                                <Setter TargetName="border2" Property="Background" Value="#101F3F" />
                                <!--<Setter TargetName="border2" Property="Background" Value="#4B8EC4" />-->
                                <Setter Property="Foreground" Value="#4B8EC4" />
                            </Trigger>

                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsChecked" Value="false" />
                                    <Condition Property="IsMouseOver" Value="True" />
                                </MultiTrigger.Conditions>
                                <MultiTrigger.Setters>
                                    <Setter TargetName="border2" Property="Background" Value="#55007acc" />
                                </MultiTrigger.Setters>
                            </MultiTrigger>

                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <!--#endregion-->

        <!--#region 下拉列表样式-->
        <Style x:Key="ToggleButtonStyle" TargetType="{x:Type ToggleButton}">
            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
            <Setter Property="Height" Value="80" />
            <Setter Property="HorizontalContentAlignment" Value="Right" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="Padding" Value="10,10" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <Grid>
                            <Border
                                x:Name="border2"
                                Margin="{TemplateBinding Padding}"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                Background="{TemplateBinding Background}">
                                <ContentPresenter
                                    Margin="{TemplateBinding Padding}"
                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                    RecognizesAccessKey="True"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            </Border>
                        </Grid>

                        <ControlTemplate.Triggers>
                            <Trigger Property="IsPressed" Value="true">
                                <Setter Property="Background" Value="#FFd2e7f4" />
                            </Trigger>
                            <Trigger Property="IsChecked" Value="true">
                                <Setter TargetName="border2" Property="Background" Value="{StaticResource ResourceKey=leftImage}" />
                            </Trigger>
                            <Trigger Property="IsChecked" Value="false">
                                <!--<Setter TargetName="border2" Property="Background" Value="#191E36" />-->
                                <Setter TargetName="border2" Property="Background" Value="#4B8EC4" />

                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="White" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="ExpanderStyle" TargetType="{x:Type Expander}">
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="VerticalContentAlignment" Value="Stretch" />
            <Setter Property="BorderBrush" Value="Transparent" />
            <Setter Property="BorderThickness" Value="1" />

            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Expander}">
                        <DockPanel>
                            <ToggleButton
                                x:Name="HeaderSite"
                                Height="40"
                                MinWidth="0"
                                MinHeight="0"
                                Margin="1"
                                Padding="{TemplateBinding Padding}"
                                HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                Content="{TemplateBinding Header}"
                                ContentTemplate="{TemplateBinding HeaderTemplate}"
                                ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                                DockPanel.Dock="Top"
                                FontFamily="{TemplateBinding FontFamily}"
                                FontSize="{TemplateBinding FontSize}"
                                FontStretch="{TemplateBinding FontStretch}"
                                FontStyle="{TemplateBinding FontStyle}"
                                FontWeight="{TemplateBinding FontWeight}"
                                Foreground="{TemplateBinding Foreground}"
                                IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                Style="{StaticResource ToggleButtonStyle}" />
                            <ContentPresenter
                                x:Name="ExpandSite"
                                Margin="{TemplateBinding Padding}"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                DockPanel.Dock="Left"
                                Focusable="false"
                                Visibility="Collapsed" />
                        </DockPanel>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsExpanded" Value="true">
                                <Setter TargetName="ExpandSite" Property="Visibility" Value="Visible" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <!--#endregion-->

    </UserControl.Resources>

    <Grid>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <!--  侧边栏菜单设置  -->
        <ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
            <Grid>
                <ItemsControl ItemsSource="{Binding Devices}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Expander
                                x:Name="E1"
                                IsExpanded="{Binding IsChecked}"
                                Style="{DynamicResource ExpanderStyle}">
                                <Expander.Header>
                                    <TextBlock
                                        HorizontalAlignment="Center"
                                        VerticalAlignment="Center"
                                        FontSize="18"
                                        Foreground="White"
                                        Text="{Binding Name}" />
                                </Expander.Header>

                                <ItemsControl Margin="0,0,0,10" ItemsSource="{Binding DeviceMonitors}">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <RadioButton
                                                Command="{Binding DataContext.DeviceWindowSwitch, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ScrollViewer}}"
                                                CommandParameter="{Binding Namespace}"
                                                Content="{Binding Name}"
                                                GroupName="All"
                                                IsChecked="{Binding IsChecked}"
                                                Style="{StaticResource RadioMiniButtonStyle}" />
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>

                            </Expander>

                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </Grid>
        </ScrollViewer>
        <!--#endregion-->

        <ContentControl Grid.Column="1" Content="{Binding MainContent}" />

    </Grid>
</UserControl>
