<UserControl x:Class="MeterVision.Station.UCStationGrid"
             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:MeterVision.Station"
             mc:Ignorable="d" 
             Background="White"
             BorderThickness="0"
             Padding="5"
             BorderBrush="#E0E0E0"             
             d:DesignHeight="800" d:DesignWidth="1000">
    <UserControl.Resources>
        <Style TargetType="ContextMenu">
            <Setter Property="Background" Value="White"/>
            <Setter Property="BorderBrush" Value="#DDDDDD"/>
            <Setter Property="BorderThickness" Value="1"/>
        </Style>

        <Style TargetType="MenuItem">
            <Setter Property="Padding" Value="5,2"/>
            <!--<Setter Property="Icon" Value="{StaticResource DefaultIcon}"/>-->
        </Style>
    </UserControl.Resources>
    
    <Grid>
        <DataGrid Name="dgStation" GridLinesVisibility="All" HorizontalGridLinesBrush="#D3D3D3" VerticalGridLinesBrush="#D3D3D3" RowHeight="30" BorderBrush="#D3D3D3"
                  HeadersVisibility="Column" SelectionMode="Single" SelectionUnit="FullRow" HorizontalScrollBarVisibility="Auto" CanUserResizeColumns="False"  
                  FrozenColumnCount="5"
                  SelectedItem="{Binding SelectedStationItem,Mode=TwoWay}"
                  AutoGenerateColumns="False" CanUserAddRows="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="White">
            <DataGrid.Resources>
                <Style TargetType="DataGridColumnHeader">
                    <Setter Property="Height" Value="40" />
                    <!--Setter Property="Background" Value="White" /-->
                    <Setter Property="Foreground" Value="Black" />
                    <Setter Property="FontSize" Value="13px" />
                    <Setter Property="FontWeight" Value="Bold" />
                    <Setter Property="BorderBrush" Value="#D3D3D3" />
                    <Setter Property="BorderThickness" Value="0,0,1,1" />
                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
                <!-- 自定义行的选中样式 -->
                <Style TargetType="DataGridRow">
                    <Style.Triggers>
                        <!-- 当行被选中时 -->
                        <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True">
                            <!-- 设置选中行的背景色 -->
                            <Setter Property="Background" Value="AliceBlue"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>

                <!-- 自定义选中单元格的背景色 -->
                <Style TargetType="DataGridCell">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True">
                            <!-- 设置选中单元格的背景色 -->
                            <Setter Property="Background" Value="AliceBlue"/>
                            <Setter Property="BorderBrush" Value="Transparent" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.Resources>

            <DataGrid.ContextMenu>
                <ContextMenu>
                    <!--<MenuItem x:Name="miMemo" Header="添加备注" Click="MiAddMemo_Click">
                        <MenuItem.Icon>
                            <Image Source="pack://application:,,,/MeterVision;component/Assest/memo.png" Width="16" Height="16"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <Separator/>-->
                    <!--<MenuItem x:Name="miUpdate" Header="修改参数" Click="MiUpdate_Click" >
                        <MenuItem.Icon>
                            <Image Source="pack://application:,,,/MeterVision;component/Assest/mi_update1.png" Width="16" Height="16"/>
                        </MenuItem.Icon>
                    </MenuItem>
                    <Separator/>-->
                    <MenuItem x:Name="miDelete" Header="删除站点" Click="MiDelete_Click">
                        <MenuItem.Icon>
                            <Image Source="pack://application:,,,/MeterVision;component/Assest/mi_delete.png" Width="16" Height="16"/>
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>
            </DataGrid.ContextMenu>

            <DataGrid.Columns>
                <!--使用自定义模板-->
                <DataGridTemplateColumn Header="序号" Width="50">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Index}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="站点" Width="100">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <!--<TextBlock Text="{Binding StationId}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>-->
                            <TextBlock Text="{Binding StationId}" FontSize="13px" Foreground="{Binding StationIdColor}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="标注" Width="50">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding MarkCountName}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="编辑" Width="60" Visibility="Collapsed">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Vertical" VerticalAlignment="Center">
                                <Button x:Name="btnUpdateStation" Width="Auto" FontSize="13px" Content="编辑" Foreground="#2196F3" VerticalAlignment="Center"
                                        BorderBrush="Transparent" BorderThickness="0 0 0 0" Background="Transparent" Margin="0 0 0 0"
                                        Click="BtnUpdateStation_Click"  />
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="删除" Width="50">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Vertical" VerticalAlignment="Center">
                                <Button x:Name="btnDeleteStation" Width="Auto" FontSize="13px" Content="删除" Foreground="#2196F3" VerticalAlignment="Center"
                                        BorderBrush="Transparent" BorderThickness="0 0 0 0" Background="Transparent" Margin="0 0 0 0"
                                        Click="BtnDeleteStation_Click"  />
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="表类型" Width="80" Visibility="Collapsed">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding MeterTypeName}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="图片亮度" Width="70" Visibility="Collapsed">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding BrightVal}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="每小时流量" Width="100" Visibility="Collapsed">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding FlowRate}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="数字+指针个数" Width="120" Visibility="Collapsed">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding CountName}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>


                <DataGridTemplateColumn Header="尾数单位" Width="100" Visibility="Collapsed">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding LastUnitName}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="表底读数" Width="100" Visibility="Collapsed">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding LastValueName}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="读数时间" Width="150" Visibility="Collapsed">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding LastTime}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>


                <DataGridTemplateColumn Header="表盘区域" Width="120" Visibility="Collapsed">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding DialRegion}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="数字区域 \ 指针坐标" Width="220" Visibility="Collapsed">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding FeatureRegionName}" FontSize="13px" Foreground="#000000" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

            </DataGrid.Columns>

        </DataGrid>

    </Grid>
</UserControl>
