<UserControl x:Class="ScratchNet.TextBoxExpressionHolder"
             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" 
             mc:Ignorable="d" 
             BorderBrush="Transparent"
             BorderThickness="1" 
             xmlns:script="clr-namespace:ScratchNet"
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <script:IsExpressionConverter x:Key="IsExpressionConverter"/>
        <script:IsNotExpressionConverter x:Key="IsNotExpressionConverter"/>
        <script:ExpressionBarBackground x:Key="BarBackgroudConverter"/>
        <script:CanBooleanConverter x:Key="CanBooleanConverter"/>
        <script:CanNotBooleanConverter x:Key="CanNotBooleanConverter"/>
        <script:CanNumberConverter x:Key="CanNumberConverter"/>
        <script:ExpressionHolderBorderConverter x:Key="ExpressionHolderBorderConverter"/>
        <script:ExpressionHolderBorderBrushConverter x:Key="BorderBrushConverter"/>
        <script:StringLiteralConverter x:Key="LiterfalConverter"/>
        <script:CanNotBooleanNumberConverter x:Key="CanNotBooleanNumberConverter"/>
    </UserControl.Resources>
    <Grid>
        <Grid Name="GridHolder" Margin="1" DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
              Visibility="{Binding Path=ExpressionDescriptor.Value, Converter={StaticResource IsNotExpressionConverter}}" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>
            <Border Grid.Column="1" Grid.Row="0" Background="White" DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                     Visibility="{Binding Path=ExpressionDescriptor.Type, Converter={StaticResource CanNotBooleanConverter}}"/>
            <TextBox Name="TextBoxHolder" SnapsToDevicePixels="True" Margin="0, 0,0,0" 
                     Grid.Column="1" Grid.Row="0" MinWidth="20"
                             Padding="0" PreviewTextInput="TextBoxHolder_PreviewTextInput"
                     DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                     Background="White"  VerticalAlignment="Center"
                     BorderThickness="0"
                     Visibility="{Binding Path=ExpressionDescriptor.Type, Converter={StaticResource CanNotBooleanConverter}}"
                     Text="{Binding Path=ExpressionDescriptor.Value, Mode=TwoWay}"
                          HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
                <TextBox.Style>
                    <Style>
                        
                    </Style>
                </TextBox.Style>
            </TextBox>
            <Border SnapsToDevicePixels="True" Margin="0" Grid.Column="1" 
                    DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                    Visibility="{Binding Path=ExpressionDescriptor.Type, Converter={StaticResource CanBooleanConverter}}"
                     Background="{Binding Path=BkColor}" BorderBrush="White" BorderThickness="0,1,0,1"/>
            <Label Name="TextLabelHolder" Foreground="Black"
                   DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                   SnapsToDevicePixels="True" Margin="0, 0,0,0" 
                     Grid.Column="1" Grid.Row="0" MinWidth="20" 
                             Padding="0"
                      Visibility="{Binding Path=ExpressionDescriptor.Type, Converter={StaticResource CanBooleanConverter}}"
                     Background="{Binding Path=BkColor}" BorderBrush="White" BorderThickness="0,1,0,1"
                     Content=" "
                          HorizontalContentAlignment="Center" VerticalContentAlignment="Stretch">
            </Label>

            <Polygon Name="Polygon1" DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                     VerticalAlignment="Stretch" Stretch="Fill" Points="0, 4, 4, 0, 4, 8" 
                     Fill="{Binding Path=BkColor}"
                     SnapsToDevicePixels="True" Width="7"
                     Visibility="{Binding Path=ExpressionDescriptor.Type, Converter={StaticResource CanBooleanConverter}}"
                             />
            <Polyline Name="Polyline1" 
                      DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                      VerticalAlignment="Stretch" Stretch="Fill" Points="4, 0, 0, 4,  4, 8" 
                     Stroke="LightGray"
                     SnapsToDevicePixels="True" Width="7" 
                     Visibility="{Binding Path=ExpressionDescriptor.Type, Converter={StaticResource CanBooleanConverter}}"
                             />
            <Polygon Name="Polygon2" 
                     DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                     VerticalAlignment="Stretch" Stretch="Fill" Grid.Column="2"
                     Points="0, 0, 0, 8, 4, 4" Fill="{Binding Path=BkColor}" SnapsToDevicePixels="True" Width="7"
                     Visibility="{Binding Path=ExpressionDescriptor.Type, Converter={StaticResource CanBooleanConverter}}"
                             /> 
            <Polyline Name="Polyline2"
                      DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                      VerticalAlignment="Stretch" Stretch="Fill" Grid.Column="2" 
                     Stroke="LightGray"
                     Points="0, 0, 4, 4, 0, 8"  SnapsToDevicePixels="True" Width="7"
                     Visibility="{Binding Path=ExpressionDescriptor.Type, Converter={StaticResource CanBooleanConverter}}"
                             />
            <Border Name="Border1" 
                    DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                    VerticalAlignment="Stretch" CornerRadius="8,0,0,8 " Width="5" Grid.Column="0" Background="White" SnapsToDevicePixels="True" Visibility="{Binding Path=ExpressionDescriptor.Type, Converter={StaticResource CanNumberConverter}}"
                            />
            <Border Name="Border2" 
                    DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                    VerticalAlignment="Stretch" CornerRadius="0,8,8,0 " Width="5" Grid.Column="2" Background="White" SnapsToDevicePixels="True" Visibility="{Binding Path=ExpressionDescriptor.Type, Converter={StaticResource CanNumberConverter}}"
                            />
            <Border Name="Border11" 
                    DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                    VerticalAlignment="Stretch" CornerRadius="2,0,0,2 " Width="5" Grid.Column="0" Background="White" SnapsToDevicePixels="True" Visibility="{Binding Path=ExpressionDescriptor.Type, Converter={StaticResource CanNotBooleanNumberConverter}}"
                            />
            <Border Name="Border21" 
                    DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                    VerticalAlignment="Stretch" CornerRadius="0,2,2,0 " Width="5" Grid.Column="2" Background="White" SnapsToDevicePixels="True" Visibility="{Binding Path=ExpressionDescriptor.Type, Converter={StaticResource CanNotBooleanNumberConverter}}"
                            />
        </Grid>
        <script:ExpressionControl x:Name="ChildExpressionControl" Margin="0" 
                                  DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                                          Expression="{Binding Path=ExpressionDescriptor.Value}" 
                                          Visibility="{Binding Path=ExpressionDescriptor.Value, Converter={StaticResource IsExpressionConverter}}" 
                                          />
    </Grid>
</UserControl>
