<UserControl x:Class="NEIntelligentControl2.Views.Alarm.RealTimeFalutInfoView"
             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.Alarm"
             mc:Ignorable="d" 
             d:DesignHeight="800" d:DesignWidth="595" Width="595" Height="800" Background="#FFE3E3E3">
    <UserControl.Resources>
        <ControlTemplate x:Key="unfixed">
            <Viewbox>
                <Canvas Width="1024" Height="1024" Background="#01FFFFFF">
                    <Path Fill="#CC464646" Data="M187.690667 874.709333h-0.277334a37.504 37.504 0 0 1-26.602666-11.264 37.845333 37.845333 0 0 1-3.904-49.877333l166.762666-229.76-125.013333-125.056a38.229333 38.229333 0 0 1-6.058667-46.336 140.8 140.8 0 0 1 53.504-45.674667 154.24 154.24 0 0 1 67.84-15.552 161.792 161.792 0 0 1 51.84 8.533334l6.4 0.661333c5.781333 0.405333 10.901333 0.981333 15.701334 1.749333a161.877333 161.877333 0 0 0 104.277333-47.253333 144.874667 144.874667 0 0 0 58.474667-90.346667c0-5.802667 0-11.904-0.234667-17.664a80.576 80.576 0 0 1 15.658667-74.858666A84.949333 84.949333 0 0 1 626.858667 106.666667a85.525333 85.525333 0 0 1 54.08 19.328l1.962666 1.941333c18.88 18.432 207.253333 206.933333 209.066667 208.746667A85.930667 85.930667 0 0 1 917.333333 397.888a85.973333 85.973333 0 0 1-25.6 61.205333 67.456 67.456 0 0 1-46.549333 16.874667 199.210667 199.210667 0 0 1-30.229333-3.008 226.176 226.176 0 0 0-15.701334-0.362667h-1.493333a115.605333 115.605333 0 0 0-77.930667 45.205334 210.752 210.752 0 0 0-59.456 118.976c0.917333 7.850667 2.56 21.333333 2.858667 23.125333a144.298667 144.298667 0 0 1-57.258667 165.056 38.229333 38.229333 0 0 1-20.138666 5.717333 38.058667 38.058667 0 0 1-27.093334-11.2l-123.562666-123.733333L209.92 866.986667a36.266667 36.266667 0 0 1-22.229333 7.722666z"/>
                </Canvas>
            </Viewbox>
        </ControlTemplate>

        <ControlTemplate x:Key="fixed">
            <Viewbox>
                <Canvas Width="1024" Height="1024" Background="#01FFFFFF">
                    <Path Fill="#CC464646" Data="m559.42 1006.7-0.19651 0.1957a37.504 37.504 45 0 1-26.798 10.792 37.845 37.845 0 0 1-37.963-32.585l-43.975-280.47-176.83-0.3904a38.229 38.229 0 0 1-36.991-28.556 140.8 140.8 0 0 1 5.679-70.118 154.24 154.24 0 0 1 37.093-58.892 161.79 161.79 0 0 1 42.753-30.535l5.0014-4.0477c4.3824-3.7925 8.4166-6.9974 12.36-9.8404a161.88 161.88 0 0 0 40.54-107.07 144.87 144.87 0 0 0-22.322-105.28c-4.0947-4.1115-8.4002-8.4345-12.631-12.35a80.576 80.576 0 0 1-41.73-64.091 84.949 84.949 0 0 1 25.195-60.862 85.525 85.525 0 0 1 51.957-24.468l2.7606-9e-3c26.384-0.26304 292.87 0.37037 295.44 0.37559a85.931 85.931 0 0 1 61.163 25.467 85.973 85.973 0 0 1 25.052 61.432 67.456 67.456 0 0 1-21.074 44.805 199.21 199.21 0 0 1-23.542 19.2 226.18 226.18 0 0 0-11.381 10.823l-1.0581 1.0538a115.61 115.61 0 0 0-23.318 87.023 210.75 210.75 0 0 0 41.83 126.26c6.1899 4.9152 16.868 13.309 18.344 14.368a144.3 144.3 45 0 1 75.904 157.36 38.229 38.229 0 0 1-10.235 18.262 38.059 38.059 0 0 1-27.1 11.183l-174.86-0.47738-38.766 280.29a36.267 36.267 0 0 1-10.301 21.158z"/>
                </Canvas>
            </Viewbox>
        </ControlTemplate>

        <Style TargetType="{x:Type ScrollBar}">
            <Setter Property="Background" Value="#77F0F8FF"/>
            <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/>
            <Setter Property="Stylus.IsFlicksEnabled" Value="false"/>
            <!--滚动条宽度-->
            <Setter Property="Width" Value="8"/>
            <Setter Property="MinWidth" Value="6"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ScrollBar}">
                        <!--滚动条背景色-->
                        <Grid x:Name="Bg" Background="#77DDDDDD" SnapsToDevicePixels="true" Width="8">
                            <Grid.RowDefinitions>
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <Track x:Name="PART_Track" IsDirectionReversed="true" IsEnabled="{TemplateBinding IsMouseOver}">
                                <Track.DecreaseRepeatButton>
                                    <RepeatButton Command="{x:Static ScrollBar.PageUpCommand}" Style="{StaticResource VerticalScrollBarPageButton}"/>
                                </Track.DecreaseRepeatButton>
                                <Track.IncreaseRepeatButton>
                                    <RepeatButton Command="{x:Static ScrollBar.PageDownCommand}" Style="{StaticResource VerticalScrollBarPageButton}"/>
                                </Track.IncreaseRepeatButton>
                                <Track.Thumb>
                                    <Thumb Style="{StaticResource ScrollBarThumb}"/>
                                </Track.Thumb>
                            </Track>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Background" TargetName="Bg" Value="{StaticResource ScrollBarDisabledBackground}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="Orientation" Value="Horizontal">
                    <Setter Property="Width" Value="Auto"/>
                    <Setter Property="MinWidth" Value="0"/>
                    <Setter Property="Height" Value="6"/>
                    <Setter Property="MinHeight" Value="6"/>
                    <Setter Property="Background" Value="#77F0F8FF"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ScrollBar}">
                                <Grid x:Name="Bg" Background="Red" SnapsToDevicePixels="true">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>
                                    <Track x:Name="PART_Track"  IsEnabled="{TemplateBinding IsMouseOver}">
                                        <Track.DecreaseRepeatButton>
                                            <RepeatButton Command="{x:Static ScrollBar.PageLeftCommand}" Style="{StaticResource HorizontalScrollBarPageButton}"/>
                                        </Track.DecreaseRepeatButton>
                                        <Track.IncreaseRepeatButton>
                                            <RepeatButton Command="{x:Static ScrollBar.PageRightCommand}" Style="{StaticResource HorizontalScrollBarPageButton}"/>
                                        </Track.IncreaseRepeatButton>
                                        <Track.Thumb>
                                            <Thumb Style="{StaticResource ScrollBarThumb}" />
                                        </Track.Thumb>
                                    </Track>
                                </Grid>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsEnabled" Value="false">
                                        <Setter Property="Background" TargetName="Bg" Value="{StaticResource ScrollBarDisabledBackground}"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="RealTimeButtonStyle" TargetType="{x:Type Button}">
            <Setter Property="Background" Value="#FF636363"/>
            <Setter Property="Foreground" Value="WhiteSmoke"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="17,4"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="true" CornerRadius="3">
                            <ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Background" TargetName="border" Value="#FF828282"/>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="true">
                                <Setter Property="Background" TargetName="border" Value="#FF636363"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="HistoryButtonStyle" TargetType="{x:Type Button}">
            <Setter Property="Background" Value="#FF006ACC"/>
            <Setter Property="Foreground" Value="WhiteSmoke"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="17,4"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="true" CornerRadius="3">
                            <ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Background" TargetName="border" Value="#FF2E81CC"/>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="true">
                                <Setter Property="Background" TargetName="border" Value="#FF006ACC"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </UserControl.Resources>
    <Grid Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Border CornerRadius="7,7,0,0" Margin="0,5,0,0">
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="WhiteSmoke"/>
                    <GradientStop Color="#FFBDBDBD" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>
            <Grid>
                <TextBlock Margin="10" FontSize="14" VerticalAlignment="Center">
                    <TextBlock.Style>
                        <Style TargetType="TextBlock">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding RelativeSource= {RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=IsFault}" Value="True">
                                    <Setter Property="Text" Value="最近报警"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding RelativeSource= {RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=IsFault}" Value="False">
                                    <Setter Property="Text" Value="最近故障"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                </TextBlock>
                <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" VerticalAlignment="Center" Margin="10,5">
                    <Button Click="Button_Click" Tag="fault" Padding="12,3" FontSize="14" Margin="3">
                        <Button.Style>
                            <Style TargetType="Button">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding RelativeSource= {RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=IsFault}" Value="True">
                                        <Setter Property="Content" Value="查看故障"/>
                                        <Setter Property="Background" Value="#FFED602A"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding RelativeSource= {RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=IsFault}" Value="False">
                                        <Setter Property="Content" Value="查看报警"/>
                                        <Setter Property="Background" Value="#FFEDA72A"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Button.Style>
                    </Button>
                    <ContentControl x:Name="cc" MouseLeftButtonUp="cc_MouseLeftButtonUp" HorizontalAlignment="Right" VerticalAlignment="Top" Width="25" Height="25">
                        <ContentControl.Style>
                            <Style TargetType="ContentControl">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=IsFixed}" Value="True">
                                        <Setter Property="Template" Value="{DynamicResource fixed}"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=IsFixed}" Value="False">
                                        <Setter Property="Template" Value="{DynamicResource unfixed}"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </ContentControl.Style>
                    </ContentControl>
                </StackPanel>
            </Grid>
        </Border>

        <DataGrid x:Name="_GDFault" Grid.Row="1" AutoGenerateColumns="False" BorderBrush="#FFABABAB" IsReadOnly="True" HorizontalGridLinesBrush="#FFA4A4A4" VerticalGridLinesBrush="#FFA4A4A4" SelectionUnit="Cell">
            <DataGrid.Style>
                <Style TargetType="DataGrid">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource= {RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=IsFault}" Value="True">
                            <Setter Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding RelativeSource= {RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=IsFault}" Value="False">
                            <Setter Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.Style>
            <DataGrid.Columns>
                <DataGridTextColumn Header="时间" Binding="{Binding AlertTimeString}" Width="127"/>
                <DataGridTextColumn Header="设备" Binding="{Binding ThingName}" Width="120"/>
                <DataGridTextColumn Header="故障信息" Binding="{Binding AlertString}" Width="260"/>
                <DataGridTemplateColumn Header="当前报警">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Grid Background="#01FFFFFF" MouseLeftButtonUp="Grid_MouseLeftButtonUp">
                                <TextBlock Text="{Binding AgCount}" Foreground="#FF4040DA" HorizontalAlignment="Center" TextDecorations="Underline"/>
                            </Grid>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>

        <DataGrid x:Name="_GDAlarm" Grid.Row="1" AutoGenerateColumns="False" BorderBrush="#FFABABAB" IsReadOnly="True" HorizontalGridLinesBrush="#FFA4A4A4" VerticalGridLinesBrush="#FFA4A4A4" SelectionUnit="CellOrRowHeader">
            <DataGrid.Style>
                <Style TargetType="DataGrid">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource= {RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=IsFault}" Value="False">
                            <Setter Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding RelativeSource= {RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=IsFault}" Value="True">
                            <Setter Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.Style>
            <DataGrid.Columns>
                <DataGridTextColumn Header="时间" Binding="{Binding LatestUpdateTimeString}" Width="127"/>
                <DataGridTextColumn Header="设备" Binding="{Binding ObjectName}" Width="120"/>
                <DataGridTextColumn Header="报警信息" Binding="{Binding AlertText}" Width="320"/>
            </DataGrid.Columns>
        </DataGrid>

        <StackPanel Grid.Row="2" Orientation="Horizontal" Margin="10" HorizontalAlignment="Center">
            <Button Style="{DynamicResource RealTimeButtonStyle}" Content="实时报警" Margin="10,0" Click="Button_Click" Tag="rtalarm"/>
            <Button Content="历史报警" Margin="10,0" Style="{DynamicResource HistoryButtonStyle}" Click="Button_Click" Tag="hisalarm"/>
            <Button Content="历史故障" Margin="10,0" Style="{DynamicResource HistoryButtonStyle}" Click="Button_Click" Tag="hisfault"/>
        </StackPanel>
    </Grid>
</UserControl>
