<!-- Copyright © Northwoods Software Corporation, 2008-2026. All Rights Reserved. -->

<UserControl x:Class="PERT.PERT"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:go="http://schemas.nwoods.com/GoXam"
    xmlns:local="clr-namespace:PERT">

  <UserControl.Resources>
    <!-- This converts the Data.Critical flag to a node background brush -->
    <go:BooleanBrushConverter x:Key="myNodeConverter"
                              TrueBrush="Red" FalseBrush="Blue" />

    <!-- This converts the Data.Critical flag of the two connected nodes to a link stroke brush -->
    <local:LinkConverter x:Key="myLinkConverter"
                              TrueBrush="Red" FalseBrush="Blue" />
    
    <DataTemplate x:Key="NodeTemplate">
      <Border BorderThickness="1"
              BorderBrush="{Binding Path=Data.Critical, Converter={StaticResource myNodeConverter}}">
        <Grid>
          <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
          </Grid.RowDefinitions>
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
          </Grid.ColumnDefinitions>
          <TextBlock Grid.Row="0" Grid.Column="0" Margin="5" TextAlignment="Center"
                     Text="{Binding Path=Data.EarlyStart}" />
          <Rectangle Grid.Row="0" Grid.Column="1"
                     Fill="Black" Width="1" HorizontalAlignment="Stretch"/>
          <TextBlock Grid.Row="0" Grid.Column="2" Margin="5" TextAlignment="Center"
                     Text="{Binding Path=Data.Length}" />
          <Rectangle Grid.Row="0" Grid.Column="3"
                     Fill="Black" Width="1" HorizontalAlignment="Stretch"/>
          <TextBlock Grid.Row="0" Grid.Column="4" Margin="5" TextAlignment="Center"
                     Text="{Binding Path=Data.EarlyFinish}" />

          <Rectangle Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="5"
                     Fill="Black" Height="1" HorizontalAlignment="Stretch"/>
          <TextBlock Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="5" Margin="5"
                     TextAlignment="Center" HorizontalAlignment="Stretch"
                     FontWeight="Bold" FontSize="14"
                     Text="{Binding Path=Data.Text}" />
          <Rectangle Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="5"
                     Fill="Black" Height="1" HorizontalAlignment="Stretch"/>

          <TextBlock Grid.Row="4" Grid.Column="0" Margin="5" TextAlignment="Center"
                     Text="{Binding Path=Data.LateStart}" />
          <Rectangle Grid.Row="4" Grid.Column="1"
                     Fill="Black" Width="1" HorizontalAlignment="Stretch"/>
          <TextBlock Grid.Row="4" Grid.Column="2" Margin="5" TextAlignment="Center"
                     Text="{Binding Path=Data.Slack}" />
          <Rectangle Grid.Row="4" Grid.Column="3"
                     Fill="Black" Width="1" HorizontalAlignment="Stretch"/>
          <TextBlock Grid.Row="4" Grid.Column="4" Margin="5" TextAlignment="Center"
                     Text="{Binding Path=Data.LateFinish}" />
        </Grid>
      </Border>
    </DataTemplate>
    
    <DataTemplate x:Key="LinkTemplate">
      <go:LinkPanel>
        <go:LinkShape Stroke="{Binding Path=Data, Converter={StaticResource myLinkConverter}}"
                      StrokeThickness="1" />
        <Path Fill="{Binding Path=Data, Converter={StaticResource myLinkConverter}}"
              go:LinkPanel.ToArrow="Standard" />
      </go:LinkPanel>
    </DataTemplate>
  </UserControl.Resources>

  <Grid>
    <go:Diagram x:Name="myDiagram"
                Padding="10"
                HorizontalContentAlignment="Stretch"
                VerticalContentAlignment="Stretch"
                NodeTemplate="{StaticResource NodeTemplate}"
                LinkTemplate="{StaticResource LinkTemplate}"
                IsReadOnly="True">
      <go:Diagram.Layout>
        <go:LayeredDigraphLayout />
      </go:Diagram.Layout>

      <!-- the legend -->
      <go:Node>
        <Border BorderThickness="1" BorderBrush="Gray" Background="LightBlue">
          <Grid>
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto" />
              <RowDefinition Height="Auto" />
              <RowDefinition Height="Auto" />
              <RowDefinition Height="Auto" />
              <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*" />
              <ColumnDefinition Width="Auto" />
              <ColumnDefinition Width="*" />
              <ColumnDefinition Width="Auto" />
              <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Row="0" Grid.Column="0" Margin="5" TextAlignment="Center"
                       Text="Early Start" />
            <Rectangle Grid.Row="0" Grid.Column="1"
                       Fill="Gray" Width="1" HorizontalAlignment="Stretch"/>
            <TextBlock Grid.Row="0" Grid.Column="2" Margin="5" TextAlignment="Center"
                       Text="Length" />
            <Rectangle Grid.Row="0" Grid.Column="3"
                       Fill="Gray" Width="1" HorizontalAlignment="Stretch"/>
            <TextBlock Grid.Row="0" Grid.Column="4" Margin="5" TextAlignment="Center"
                       Text="Early Finish" />

            <Rectangle Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="5"
                       Fill="Gray" Height="1" HorizontalAlignment="Stretch"/>
            <TextBlock Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="5" Margin="5"
                       TextAlignment="Center" HorizontalAlignment="Stretch"
                       FontWeight="Bold" FontSize="14"
                       Text="Activity Name" />
            <Rectangle Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="5"
                       Fill="Gray" Height="1" HorizontalAlignment="Stretch"/>

            <TextBlock Grid.Row="4" Grid.Column="0" Margin="5" TextAlignment="Center"
                       Text="Late Start" />
            <Rectangle Grid.Row="4" Grid.Column="1"
                       Fill="Gray" Width="1" HorizontalAlignment="Stretch"/>
            <TextBlock Grid.Row="4" Grid.Column="2" Margin="5" TextAlignment="Center"
                       Text="Slack" />
            <Rectangle Grid.Row="4" Grid.Column="3"
                       Fill="Gray" Width="1" HorizontalAlignment="Stretch"/>
            <TextBlock Grid.Row="4" Grid.Column="4" Margin="5" TextAlignment="Center"
                       Text="Late Finish" />
          </Grid>
        </Border>
      </go:Node>
    </go:Diagram>
  </Grid>
</UserControl>
