<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Serein.Workbench.Themes"
                    xmlns:view="clr-namespace:Serein.Workbench.Node.View"
                    xmlns:sys="clr-namespace:System;assembly=mscorlib" 
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:serein="clr-namespace:Serein.Library;assembly=Serein.Library"
                    xmlns:converter="clr-namespace:Serein.Workbench.Converters">


    <ResourceDictionary.MergedDictionaries>
    </ResourceDictionary.MergedDictionaries>

    <converter:InvertableBooleanToVisibilityConverter x:Key="InvertedBoolConverter"/>
    <converter:EnumToBooleanConverter x:Key="EnumToBooleanConverter"/>
    <converter:TypeNameDisplaynConverter x:Key="TypeNameDisplaynConverter"/>
    <local:DescriptionOrNameConverter x:Key="DescOrNameConverter"/>
    
    
    <Style TargetType="{x:Type local:MethodDetailsControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate x:Name="MethodControlTemplate" TargetType="{x:Type local:MethodDetailsControl}">
                    

                    <!--根据方法入参数量生成相应的控件-->
                    <ItemsControl ItemsSource="{Binding MethodDetails.ParameterDetailss, RelativeSource={RelativeSource TemplatedParent}}" Background="#E3FDFD" >
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <!-- 共享宽度启用 -->
                                <StackPanel Grid.IsSharedSizeScope="True" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate DataType="serein:ParameterData">
                                <Grid DataContext="{Binding}" >
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition SharedSizeGroup="Col1" Width="auto"/>
                                        <ColumnDefinition SharedSizeGroup="Col2" Width="auto"/>
                                        <ColumnDefinition SharedSizeGroup="Col3" Width="auto"/>
                                        <ColumnDefinition SharedSizeGroup="Col4" Width="auto"/>
                                        <ColumnDefinition  Width="*"/>
                                        <ColumnDefinition  Width="auto"/>

                                    </Grid.ColumnDefinitions>
                                    <!--连接控制器-->
                                    <view:ArgJunctionControl x:Name="ArgJunctionControl" Grid.Column="0" ArgIndex="{Binding Index}"
                                                             NodeViewModel="{Binding NodeViewModel, 
        RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MethodDetailsControl}}}" />

                                    <!--是否设置为显式参数-->
                                    <CheckBox  Grid.Column="1" IsChecked="{Binding IsExplicitData, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="2,0,2,0" VerticalContentAlignment="Center"/>

                                    <!--参数类型提示-->
                                    <TextBlock Grid.Column="2"  Text="{Binding DataType, Converter={StaticResource TypeNameDisplaynConverter}}"  Margin="2,0,2,0" VerticalAlignment="Center"/>
                                    
                                    
                                    <!--入参参数名称-->
                                    <ContentControl Content="{Binding}"   Grid.Column="3"   Margin="2,0,2,0" HorizontalAlignment="Left" VerticalAlignment="Center">
                                        <ContentControl.Resources>
                                            <local:DataContextProxy x:Key="Proxy"
                                                   DataContext="{Binding}" />
                                        </ContentControl.Resources>
                                        <ContentControl.Style>
                                            <Style TargetType="ContentControl">
                                                <Style.Triggers>
                                                    
                                                    <!--脚本节点输入变量名称-->
                                                    <MultiDataTrigger>
                                                        <MultiDataTrigger.Conditions>
                                                            <Condition Binding="{Binding NodeModel.ControlType}" Value="{x:Static serein:NodeControlType.Script}"/>
                                                        </MultiDataTrigger.Conditions>
                                                        <Setter Property="ContentTemplate">
                                                            <Setter.Value>
                                                                <DataTemplate>
                                                                    <TextBox MinWidth="50" Text="{Binding Name, Mode=TwoWay}"/>
                                                                </DataTemplate>
                                                            </Setter.Value>
                                                        </Setter>
                                                    </MultiDataTrigger>

                                                    <!--显示Action节点方法入参名称-->
                                                    <MultiDataTrigger>
                                                        <MultiDataTrigger.Conditions>
                                                            <Condition Binding="{Binding NodeModel.ControlType}" Value="{x:Static serein:NodeControlType.Action}"/>
                                                        </MultiDataTrigger.Conditions>
                                                        <Setter Property="ContentTemplate">
                                                            <Setter.Value>
                                                                <DataTemplate>

                                                                    <TextBlock Grid.Column="0" MinWidth="50">
                                                                        <TextBlock.Text>
                                                                            <MultiBinding Converter="{StaticResource DescOrNameConverter}">
                                                                                <Binding Path="Description"/>
                                                                                <Binding Path="Name"/>
                                                                            </MultiBinding>
                                                                        </TextBlock.Text>
                                                                    </TextBlock>
                                                                    
                                                                </DataTemplate>
                                                            </Setter.Value>
                                                        </Setter>
                                                    </MultiDataTrigger>

                                                    <!--显示Flip方法入参名称-->
                                                    <MultiDataTrigger>
                                                        <MultiDataTrigger.Conditions>
                                                            <Condition Binding="{Binding NodeModel.ControlType}" Value="{x:Static serein:NodeControlType.Flipflop}"/>
                                                        </MultiDataTrigger.Conditions>
                                                        <Setter Property="ContentTemplate">
                                                            <Setter.Value>
                                                                <DataTemplate>
                                                                    
                                                                    <TextBlock Grid.Column="0" MinWidth="50">
                                                                        <TextBlock.Text>
                                                                            <MultiBinding Converter="{StaticResource DescOrNameConverter}">
                                                                                <Binding Path="Description"/>
                                                                                <Binding Path="Name"/>
                                                                            </MultiBinding>
                                                                        </TextBlock.Text>
                                                                    </TextBlock>
                                                                    
                                                                </DataTemplate>
                                                            </Setter.Value>
                                                        </Setter>
                                                    </MultiDataTrigger>

                                                    <!--显示FlowCall节点方法入参名称-->
                                                    <MultiDataTrigger>
                                                        <MultiDataTrigger.Conditions>
                                                            <Condition Binding="{Binding NodeModel.ControlType}" Value="{x:Static serein:NodeControlType.FlowCall}"/>
                                                        </MultiDataTrigger.Conditions>
                                                        <Setter Property="ContentTemplate">
                                                            <Setter.Value>
                                                                <DataTemplate>

                                                                    <TextBlock Grid.Column="0" MinWidth="50">
                                                                        <TextBlock.Text>
                                                                            <MultiBinding Converter="{StaticResource DescOrNameConverter}">
                                                                                <Binding Path="Description"/>
                                                                                <Binding Path="Name"/>
                                                                            </MultiBinding>
                                                                        </TextBlock.Text>
                                                                    </TextBlock>

                                                                </DataTemplate>
                                                            </Setter.Value>
                                                        </Setter>
                                                    </MultiDataTrigger>
                                                    
                                                </Style.Triggers>
                                            </Style>
                                        </ContentControl.Style>
                                    </ContentControl>
                                    
                                    
                                    <!--增加可选参数（如果有）-->
                                    <view:ParamsArgControl x:Name="ParamsArgControl"
                                                           ArgIndex="{Binding Index}"
                                                           MyNode="{Binding NodeModel}"
                                                           Width="12"
                                                           Grid.Column="5"  Margin="2,0,2,0" HorizontalAlignment="Right" VerticalAlignment="Center"
                                                           Visibility="{Binding IsParams, Mode=OneWay, 
                                                           Converter={StaticResource InvertedBoolConverter},ConverterParameter=Normal}" 
                                     />
                                    
                                    <ContentControl Content="{Binding}"  Grid.Column="4" VerticalAlignment="Center">
                                        <ContentControl.Style>
                                            <Style TargetType="ContentControl">
                                                <Style.Triggers>
                                                    <!--无须指定参数-->
                                                    <MultiDataTrigger>
                                                        <MultiDataTrigger.Conditions>
                                                            <Condition Binding="{Binding IsExplicitData}" Value="false" />
                                                        </MultiDataTrigger.Conditions>
                                                        <Setter Property="ContentTemplate">
                                                            <Setter.Value>
                                                                <DataTemplate>
                                                                    <Grid>
                                                                        <Grid.ColumnDefinitions>
                                                                            <ColumnDefinition Width="*"/>
                                                                        </Grid.ColumnDefinitions>
                                                                        <TextBlock Grid.Column="0" MinWidth="50" Text="无须指定参数"/>
                                                                    </Grid>
                                                                </DataTemplate>
                                                            </Setter.Value>
                                                        </Setter>
                                                    </MultiDataTrigger>

                                                    <!--指定参数：选项类型-->
                                                    <MultiDataTrigger>
                                                        <MultiDataTrigger.Conditions>
                                                            <Condition Binding="{Binding IsExplicitData}" Value="true" />
                                                            <Condition Binding="{Binding InputType}" Value="Select" />
                                                        </MultiDataTrigger.Conditions>
                                                        <Setter Property="ContentTemplate">
                                                            <Setter.Value>
                                                                <DataTemplate>
                                                                    <Grid>
                                                                        <Grid.ColumnDefinitions>
                                                                            <ColumnDefinition Width="*"/>
                                                                        </Grid.ColumnDefinitions>
                                                                        <ComboBox  Grid.Column="0"
                                                                                   MinWidth="50"
                                                                                   ItemsSource="{Binding Items}"
                                                                                   SelectedItem="{Binding DataValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                                                                    </Grid>
                                                                </DataTemplate>
                                                            </Setter.Value>
                                                        </Setter>
                                                    </MultiDataTrigger>

                                                    <!--指定参数：文本类型（可输入）-->
                                                    <MultiDataTrigger>
                                                        <MultiDataTrigger.Conditions>
                                                            <Condition Binding="{Binding IsExplicitData}" Value="true" />
                                                            <Condition Binding="{Binding InputType}" Value="Input" />
                                                        </MultiDataTrigger.Conditions>
                                                        <Setter Property="ContentTemplate">
                                                            <Setter.Value>
                                                                <DataTemplate>
                                                                    <Grid>
                                                                        <Grid.ColumnDefinitions>
                                                                            <ColumnDefinition Width="*"/>
                                                                        </Grid.ColumnDefinitions>
                                                                        <TextBox   Grid.Column="0" MinWidth="50" Text="{Binding DataValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                                                                    </Grid>
                                                                </DataTemplate>
                                                            </Setter.Value>
                                                        </Setter>
                                                    </MultiDataTrigger>

                                                </Style.Triggers>
                                            </Style>
                                        </ContentControl.Style>
                                    </ContentControl>
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
