<ui:ContentDialog x:Class="DMS.WPF.Views.Dialogs.ImportExcelDialog"
                  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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                  xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
                  xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
                  xmlns:vmd="clr-namespace:DMS.WPF.ViewModels.Dialogs"
                  xmlns:helper="clr-namespace:DMS.WPF.Helper"
                  Title="从Excel导入"
                  CloseButtonText="取消"
                  DefaultButton="Primary"
                  PrimaryButtonText="导入全部"
                  SecondaryButtonText="导入选择"
                  d:DataContext="{d:DesignInstance vmd:ImportExcelDialogViewModel}"
                  mc:Ignorable="d"
                  AllowDrop="True"
                  DragEnter="Dialog_DragEnter"
                  Drop="Dialog_Drop">

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="PrimaryButtonClick">
            <i:InvokeCommandAction Command="{Binding ImportAllCommand}" />
        </i:EventTrigger>
        <i:EventTrigger EventName="SecondaryButtonClick">
            <i:InvokeCommandAction Command="{Binding ImportSelectedCommand}" />
        </i:EventTrigger>
        <i:EventTrigger EventName="CloseButtonClick">
            <i:InvokeCommandAction Command="{Binding CancleButtonCommand}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>

    <Grid Margin="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <StackPanel Grid.Row="0">
            <TextBlock HorizontalAlignment="Center"
                       Text="拖放Excel文件到此处或选择文件" />
            <Grid Margin="0,10,0,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBox Grid.Column="0"
                         VerticalAlignment="Center"
                         Text="{Binding FilePath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <Button Grid.Column="1"
                        Margin="5,0,0,0"
                        Click="SelectFile_Click"
                        Content="选择文件" />
            </Grid>
        </StackPanel>

        <DataGrid Grid.Row="1"
                  Margin="0,10,0,0"
                  ItemsSource="{Binding VariableItemViewModels}"
                  AutoGenerateColumns="False"
                  CanUserAddRows="False">
            <i:Interaction.Behaviors>
                <helper:SelectedItemsBehavior SelectedItems="{Binding SelectedVariables}" />
            </i:Interaction.Behaviors>
            <DataGrid.Style>
                <Style BasedOn="{StaticResource {x:Type DataGrid}}"
                       TargetType="DataGrid">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding VariableItemViewModels.Count}"
                                     Value="0">
                            <Setter Property="Visibility"
                                    Value="Collapsed" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.Style>
            <DataGrid.Columns>
                <DataGridTextColumn Header="名称"
                                    Binding="{Binding Name}" />
                <DataGridTextColumn Header="描述"
                                    Binding="{Binding Description}" />
                <DataGridTextColumn Header="数据类型"
                                    Binding="{Binding CSharpDataType}" />
                <DataGridTextColumn Header="S7地址"
                                    Binding="{Binding S7Address}" />
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</ui:ContentDialog>