<Window x:Class="Serein.WorkBench.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Serein.WorkBench"
        xmlns:custom="clr-namespace:Serein.WorkBench.Node.View"
        Title="Dynamic Node Flow" Height="700" Width="1200"
        AllowDrop="True" Drop="Window_Drop" DragOver="Window_DragOver"
        Loaded="Window_Loaded"
        ContentRendered="Window_ContentRendered"
        Closing="Window_Closing">

    <Window.Resources>
        <local:RightThumbPositionConverter x:Key="RightThumbPositionConverter" />
        <local:BottomThumbPositionConverter x:Key="BottomThumbPositionConverter" />
        <local:VerticalCenterThumbPositionConverter x:Key="VerticalCenterThumbPositionConverter" />
        <local:HorizontalCenterThumbPositionConverter x:Key="HorizontalCenterThumbPositionConverter" />
    </Window.Resources>

    <Window.InputBindings>
        <KeyBinding Key="Escape" Command="{Binding CancelConnectionCommand}"/>
        
        
    </Window.InputBindings>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="3*"/>
        </Grid.ColumnDefinitions>

        <DockPanel Grid.Column="0" Background="#F5F5F5">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="40"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="2*"></RowDefinition>
                    <RowDefinition Height="*"></RowDefinition>
                </Grid.RowDefinitions>
                <!--<Button Grid.Row="0" Content="Button 1"></Button>
                <Button Grid.Row="1" Content="Button 2"></Button>
                <Button Grid.Row="2" Content="Button 3"></Button>
                <Button Grid.Row="3" Content="Button 4"></Button>-->
                <!--DockPanel.Dock="Top"-->

                <Grid Margin="2,2,2,5">
                    <Button  Grid.Row="0"  Content="保存项目" Click="ButtonSaveFile_Click"  HorizontalAlignment="Left"  Margin="5,5,5,5"/>
                    <Button  Grid.Row="0"  Content="卸载清空" Click="UnloadAllButton_Click"  HorizontalAlignment="Right"  Margin="5,5,5,5"/>
                </Grid>
                
                <ScrollViewer  Grid.Row="1"  HorizontalScrollBarVisibility="Auto">
                <StackPanel  Orientation="Horizontal">
                    <!--<Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>-->

                        <custom:ExpOpNodeControl x:Name="ExpOpNodeControl" Margin="10" AllowDrop="True" PreviewMouseMove="BaseNodeControl_PreviewMouseMove"/>
                        <custom:ConditionNodeControl x:Name="ConditionNodeControl" Margin="10" AllowDrop="True" PreviewMouseMove="BaseNodeControl_PreviewMouseMove"/>
                        <custom:ConditionRegionControl  x:Name="ConditionRegionControl" Margin="10" AllowDrop="True" PreviewMouseMove="BaseNodeControl_PreviewMouseMove"/>
                        <!--<custom:ActionRegionControl x:Name="ActionRegionControl" Grid.Column="1" Margin="10" AllowDrop="True" Drop="ActionRegionControl_Drop" PreviewMouseMove="RegionControl_PreviewMouseMove"/>-->
                        <!--<TextBlock Text="触发器"  Grid.Column="2"/>-->
                        <!--<custom:StateRegionControl x:Name="StateRegionControl" Grid.Column="2" Margin="10" AllowDrop="True" Drop="StateRegionControl_Drop" PreviewMouseMove="RegionControl_PreviewMouseMove"/>-->
                    <!--</Grid>-->
                </StackPanel>
                </ScrollViewer>
                <ScrollViewer  Grid.Row="2"  VerticalScrollBarVisibility="Auto">
                    <StackPanel x:Name="DllStackPanel" Margin="5"/>
                </ScrollViewer>
            </Grid>
        </DockPanel>


        <GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ResizeBehavior="PreviousAndNext" Background="Gray"/>

        <Grid  Grid.Column="2" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="60"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
            </Grid.RowDefinitions>
            <StackPanel Grid.Row="0" Background="#F5F5F5" Orientation="Horizontal" >
                <Button x:Name="ButtonDebugRun"  Content="运行" Width="100" Margin="10" Click="ButtonDebugRun_Click"></Button>
                <Button x:Name="ButtonDebugFlipflopNode"  Content="结束" Width="100" Margin="10" Click="ButtonDebugFlipflopNode_Click"></Button>
            </StackPanel>

            <StackPanel  Grid.Row="1"
                         x:Name="FlowChartStackPanel"
                         ClipToBounds="True">
                <Canvas 
                    x:Name="FlowChartCanvas" 
                    Background="#D9FFEA"
                    AllowDrop="True" 
                    Width="1000"
                    Height="700"
                    MouseLeftButtonDown ="FlowChartCanvas_MouseLeftButtonDown"
                    MouseLeftButtonUp="FlowChartCanvas_MouseLeftButtonUp"
                    MouseDown="FlowChartCanvas_MouseDown"
                    MouseMove="FlowChartCanvas_MouseMove"
                    MouseUp="FlowChartCanvas_MouseUp"
                    MouseWheel="FlowChartCanvas_MouseWheel"
                    Drop="FlowChartCanvas_Drop" 
                    DragOver="FlowChartCanvas_DragOver">

                    <Rectangle x:Name="SelectionRectangle" 
                               Stroke="Blue" 
                               StrokeThickness="2" 
                               Fill="LightBlue" 
                               Opacity="0.5" 
                               Panel.ZIndex="999999"
                               Visibility="Collapsed"/> 

                    <!-- Top-Left Thumb -->
                    <!--<Thumb x:Name="TopLeftThumb" 
                           Width="10" Height="10"
                           DragDelta="Thumb_DragDelta_TopLeft"
                           Cursor="SizeNWSE"
                           Canvas.Left="0" Canvas.Top="0"/>-->

                    <!-- Top-Right Thumb -->
                    <!--<Thumb x:Name="TopRightThumb" 
                           Width="10" Height="10"
                           DragDelta="Thumb_DragDelta_TopRight"
                           Cursor="SizeNESW"
                           Canvas.Left="{Binding ActualWidth, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource RightThumbPositionConverter}}" 
                           Canvas.Top="0"/>-->

                    <!-- Bottom-Left Thumb -->
                    <!--<Thumb x:Name="BottomLeftThumb" 
                           Width="10" Height="10"
                           DragDelta="Thumb_DragDelta_BottomLeft"
                           Cursor="SizeNESW"
                           Canvas.Left="0" 
                           Canvas.Top="{Binding ActualHeight, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource BottomThumbPositionConverter}}"/>-->

                    <!-- Bottom-Right Thumb -->
                    <Thumb x:Name="BottomRightThumb" 
                           Width="40" Height="40"
                           DragDelta="Thumb_DragDelta_BottomRight"
                           Cursor="SizeNWSE"
                           Canvas.Left="{Binding ActualWidth, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource RightThumbPositionConverter}}" 
                           Canvas.Top="{Binding ActualHeight, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource BottomThumbPositionConverter}}"/>

                    <!-- Left Thumb -->
                    <!--<Thumb x:Name="LeftThumb" 
                           Width="10" Height="10"
                           DragDelta="Thumb_DragDelta_Left"
                           Cursor="SizeWE"
                           Canvas.Left="0" 
                           Canvas.Top="{Binding ActualHeight, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource VerticalCenterThumbPositionConverter}}"/>-->

                    <!-- Right Thumb -->
                    <!--Canvas.Left="{Binding ActualWidth, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource RightThumbPositionConverter}}" 
Canvas.Top="{Binding ActualHeight, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource VerticalCenterThumbPositionConverter}}"-->
                    <Thumb x:Name="RightThumb" Width="5" Cursor="SizeWE" Canvas.Top="0" Canvas.Right="0" DragDelta="Thumb_DragDelta_Right">
                        <Thumb.Template>
                            <ControlTemplate>
                                <Border Background="#B1B9F8" Width="5" Height="{Binding RelativeSource={RelativeSource AncestorType=Canvas}, Path=ActualHeight}" />
                            </ControlTemplate>
                        </Thumb.Template>
                    </Thumb>

                    <!-- Top Thumb -->
                    <!--<Thumb x:Name="TopThumb" 
                           Width="10" Height="10"
                           DragDelta="Thumb_DragDelta_Top"
                           Cursor="SizeNS"
                           Canvas.Left="{Binding ActualWidth, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource HorizontalCenterThumbPositionConverter}}" 
                           Canvas.Top="0"/>-->

                    <!-- Bottom Thumb -->
                    <!--Canvas.Left="{Binding ActualWidth, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource HorizontalCenterThumbPositionConverter}}" 
 Canvas.Top="{Binding ActualHeight, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource BottomThumbPositionConverter}}"-->
                    <Thumb x:Name="BottomThumb" Height="5" Cursor="SizeNS" Canvas.Bottom="0" Canvas.Left="0"  DragDelta="Thumb_DragDelta_Bottom">
                        <Thumb.Template>
                            <ControlTemplate>
                                <Border Background="#B1B9F8" Height="5" Width="{Binding RelativeSource={RelativeSource AncestorType=Canvas}, Path=ActualWidth}" />
                            </ControlTemplate>
                        </Thumb.Template>
                    </Thumb>
                </Canvas>



                    
                
            </StackPanel>
            
            
        </Grid>
        
    </Grid>
</Window>
