<UserControl x:Class="BOB.Views.CommandTree"
             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:i="http://schemas.microsoft.com/xaml/behaviors"
             xmlns:local="clr-namespace:BOB.Views"
             xmlns:model="clr-namespace:BOB.Models"
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:prism="http://prismlibrary.com/"
             prism:ViewModelLocator.AutoWireViewModel="True"
             mc:Ignorable="d"
             d:DesignHeight="450"
             d:DesignWidth="800">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <prism:InvokeCommandAction Command="{Binding LoadedCommand}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="439*" />
            <ColumnDefinition Width="361*" />
        </Grid.ColumnDefinitions>
        <GroupBox Header="指令"
                  Grid.ColumnSpan="2">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <!-- 搜索框 -->
                <StackPanel Grid.Row="0"
                            Orientation="Horizontal"
                            Margin="10,0,7,12"
                            VerticalAlignment="Center">
                    <TextBox MinWidth="150"
                             Height="25"
                             Margin="0,0,5,0"
                             VerticalContentAlignment="Center"
                             Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}"
                             materialDesign:HintAssist.Hint="搜索内容">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="KeyDown">
                                <prism:InvokeCommandAction Command="{Binding SearchEnterCommand}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </TextBox>
                </StackPanel>

                <!-- TreeView -->
                <TreeView Grid.Row="1"
                          ItemsSource="{Binding InstructionTree}">
                    <TreeView.Resources>
                        <HierarchicalDataTemplate DataType="{x:Type model:InstructionNode}"
                                                  ItemsSource="{Binding Children}">
                            <TextBlock Text="{Binding Name}" />
                        </HierarchicalDataTemplate>
                    </TreeView.Resources>
                    <!-- 双击 -->
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="MouseDoubleClick">
                            <prism:InvokeCommandAction Command="{Binding TreeDoubleClickCommand}"
                                                       CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType=TreeView}}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>

                    <!-- 右键菜单 -->
                    <TreeView.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="重新加载"
                                      Command="{Binding ReloadCommand}" />
                        </ContextMenu>
                    </TreeView.ContextMenu>
                </TreeView>

            </Grid>
        </GroupBox>
    </Grid>
</UserControl>
