<UserControl x:Class="MyPad.Views.Regions.ScriptRunnerView"
             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:p="http://prismlibrary.com/"
             xmlns:m="http://metro.mahapps.com/winfx/xaml/controls"
             xmlns:mi="http://metro.mahapps.com/winfx/xaml/iconpacks"
             xmlns:le="http://wpflocalizeextension.codeplex.com"
             xmlns:qc="http://QuickConverter.CodePlex.com/"
             xmlns:ge="clr-namespace:SourceChord.GridExtra;assembly=GridExtra.Wpf"
             mc:Ignorable="d" 
             p:ViewModelLocator.AutoWireViewModel="True"
             d:DesignHeight="450" d:DesignWidth="800">

    <Grid ge:GridEx.RowDefinition="*, Auto">
        <TextBox Grid.Row="0"
                 Text="{Binding OutputText.Value, Mode=OneWay}"
                 IsTabStop="False"
                 IsReadOnly="True"
                 BorderThickness="0"
                 TextWrapping="Wrap"
                 VerticalContentAlignment="Bottom"
                 VerticalScrollBarVisibility="Auto"
                 HorizontalScrollBarVisibility="Hidden">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="TextChanged">
                    <i:CallMethodAction MethodName="ScrollToEnd"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </TextBox>
        <Grid Grid.Row="1" ge:GridEx.ColumnDefinition="Auto, *">
            <TextBlock Grid.Column="0" Text="> " VerticalAlignment="Center"/>
            <!-- WARN: このコントロール名は MainWindow から FindName で検索される -->
            <ComboBox Grid.Column="1" x:Name="ScriptInputField"
                      ItemsSource="{Binding ScriptHistories, Mode=OneWay}"
                      Text="{Binding Script.Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                      IsReadOnly="{Binding IsPending.Value, Mode=OneWay}"
                      IsEditable="True"
                      BorderThickness="0"
                      m:TextBoxHelper.ButtonWidth="0">
                <!-- HACK: タブを切り替えると Command が複数回起動される
                
                     タブを切り替えるたびに Command の紐づけが追加されているような挙動をしている。
                     KeyTrigger の仕様のため、代わりに KeyBinding を用いる。
                
                     ※おそらく下記と同じ現象
                       [stack overflow: Blend KeyTrigger fires multiple times: 2011-05-10]
                       https://stackoverflow.com/questions/5948158/blend-keytrigger-fires-multiple-times
                
                <i:Interaction.Triggers>
                    <i:KeyTrigger ActiveOnFocus="True" Key="Return">
                        <p:InvokeCommandAction Command="{Binding RunScriptCommand, Mode=OneTime}"/>
                    </i:KeyTrigger>
                </i:Interaction.Triggers>
                -->
                <ComboBox.InputBindings>
                    <KeyBinding Command="{Binding RunScriptCommand, Mode=OneTime}" Key="Return"/>
                </ComboBox.InputBindings>
            </ComboBox>
        </Grid>
        <Border Grid.RowSpan="2" d:IsHidden="True" Style="{StaticResource Common.Overlay}" Visibility="{qc:Binding '$P ? Visibility.Visible : Visibility.Collapsed', P={Binding IsPending.Value, Mode=OneWay}}">
            <m:ProgressRing/>
        </Border>
    </Grid>

</UserControl>
