<UserControl x:Class="BDU.Views.ParametersManager"
             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:BDU.Views"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance Type=local:ParametersManager}"
             d:DesignHeight="450"
             d:DesignWidth="800">
    <UserControl.Resources>
        <CollectionViewSource x:Key="VisibleParameters"
                              Source="{Binding Program.Parameters}">
            <CollectionViewSource.LiveFilteringProperties>
                <sys:String>IsVisible</sys:String>
            </CollectionViewSource.LiveFilteringProperties>
        </CollectionViewSource>
    </UserControl.Resources>
    <Grid>
        <GroupBox Grid.Row="3"
                  Header="设备/参数"
                  Padding="0">
            <TabControl>
                <TabItem Header="参数">
                    <DataGrid x:Name="ParameterDataGrid"
                              Padding="10"
                              Background="Transparent"
                              ItemsSource="{Binding Source={StaticResource VisibleParameters}}"
                              AutoGenerateColumns="False"
                              CanUserAddRows="False"
                              SelectionMode="Extended"
                              SelectionUnit="FullRow">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="类别"
                                                Binding="{Binding Category, Converter={StaticResource ParameterCategoryToStringConverter}}"
                                                IsReadOnly="True" />
                            <DataGridTextColumn Header="参数名"
                                                Binding="{Binding Name}"
                                                IsReadOnly="True" />
                            <DataGridTextColumn Header="类型"
                                                Binding="{Binding Type}"
                                                IsReadOnly="True" />
                            <DataGridTextColumn Header="值"
                                                MinWidth="20"
                                                Binding="{Binding Value, Converter={StaticResource ParameterValueToStringConverter}}"
                                                IsReadOnly="True" />
                        </DataGrid.Columns>
                        <DataGrid.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="新增"
                                          Click="ParameterAdd_Click" />
                                <MenuItem Header="编辑"
                                          Click="ParameterEdit_Click" />
                                <MenuItem Header="删除" Foreground="Red"
                                          Click="ParameterDelete_Click" />
                            </ContextMenu>
                        </DataGrid.ContextMenu>
                    </DataGrid>
                </TabItem>
                <TabItem Header="设备">
                    <DataGrid x:Name="DeviceDataGrid"
                              Padding="10"
                              Background="Transparent"
                              ItemsSource="{Binding Program.Devices}"
                              AutoGenerateColumns="False"
                              CanUserAddRows="False"
                              IsReadOnly="True"
                              SelectionMode="Extended"
                              SelectionUnit="FullRow">
                        <DataGrid.Columns>
                            <DataGridTemplateColumn Header="设备状态">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Grid Width="20"
                                              Height="20">
                                            <Ellipse Width="16"
                                                     Height="16"
                                                     StrokeThickness="1"
                                                     Stroke="DarkGray">
                                                <Ellipse.Style>
                                                    <Style TargetType="Ellipse">
                                                        <Setter Property="Fill"
                                                                Value="Transparent" />
                                                        <Style.Triggers>
                                                            <DataTrigger Binding="{Binding Connected}"
                                                                         Value="True">
                                                                <Setter Property="Fill"
                                                                        Value="LimeGreen" />
                                                            </DataTrigger>
                                                            <DataTrigger Binding="{Binding Connected}"
                                                                         Value="False">
                                                                <Setter Property="Fill"
                                                                        Value="Red" />
                                                            </DataTrigger>
                                                        </Style.Triggers>
                                                    </Style>
                                                </Ellipse.Style>
                                            </Ellipse>
                                        </Grid>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                            <DataGridTextColumn Header="设备名称"
                                                Binding="{Binding Name}" />
                            <DataGridTextColumn Header="备注"
                                                Binding="{Binding Description}" />
                        </DataGrid.Columns>
                        <DataGrid.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="新增"
                                          Click="DeviceAdd_Click" />
                                <MenuItem Header="编辑"
                                          Click="DeviceEdit_Click" />
                                <MenuItem Header="删除" Foreground="Red"
                                          Click="DeviceDelete_Click" />
                            </ContextMenu>
                        </DataGrid.ContextMenu>
                    </DataGrid>
                </TabItem>
            </TabControl>
        </GroupBox>
    </Grid>
</UserControl>
