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

<UserControl x:Class="Gantt.Gantt"
    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:Gantt">

  <UserControl.Resources>
    <!-- This converts coordinate systems; you need one of these per Diagram!
         This has the Space property, which governs X axis coordinates. -->
    <local:LengthConverter x:Key="myLengthConverter" />
    <!-- This converts coordinate systems; you need one of these per Diagram!
         This uses the LengthConverter for its Space property. -->
    <local:LocationConverter x:Key="myLocationConverter"
                             LenConv="{StaticResource myLengthConverter}" />
    <!-- This converts the Data.Critical flag to a node background brush -->
    <go:BooleanBrushConverter x:Key="myBackgroundConverter"
                              TrueBrush="OrangeRed" FalseBrush="MediumAquamarine" />

    <!-- Node DataTemplates -->
    <go:DataTemplateDictionary x:Key="DTD">
      <!-- the default template -->
      <DataTemplate x:Key="">
        <go:NodePanel Sizing="Fixed"
                      go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay,
                               Converter={StaticResource myLocationConverter}}"
                      go:Node.FromSpot="MiddleRight"
                      go:Node.ToSpot="0.01 0 4 0"
                      go:Part.SelectionAdorned="True">
          <Rectangle x:Name="myRectangle"
                     Fill="{Binding Path=Data.Critical,
                            Converter={StaticResource myBackgroundConverter}}"
                     Stroke="Black"
                     StrokeThickness="1"
                     Width="{Binding Path=Data.Length,
                             Converter={StaticResource myLengthConverter}}"
                     Height="15" />
          <TextBlock Text="{Binding Path=Data.Text}"
                     Margin="1 0 0 0"
                     HorizontalAlignment="Left"
                     VerticalAlignment="Center" />
        </go:NodePanel>
      </DataTemplate>

      <DataTemplate x:Key="Start">
        <go:NodeShape go:NodePanel.Figure="Diamond" Fill="Black"
                      go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay,
                               Converter={StaticResource myLocationConverter}}"
                      go:Node.LocationSpot="TopRight"
                      go:Node.FromSpot="MiddleRight"
                      go:Part.Selectable="False"
                      Width="15" Height="15" />
      </DataTemplate>

      <DataTemplate x:Key="Finish">
        <go:NodeShape go:NodePanel.Figure="Diamond" Fill="Black"
                      go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay,
                               Converter={StaticResource myLocationConverter}}"
                      go:Node.ToSpot="0.01 0 4 0"
                      go:Part.Selectable="False"
                      Width="15" Height="15" />
      </DataTemplate>
      
      <DataTemplate x:Key="Week">
        <TextBlock Text="{Binding Path=Data.Text}" 
                   go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay,
                            Converter={StaticResource myLocationConverter}}" />
      </DataTemplate>
    </go:DataTemplateDictionary>
    
    <DataTemplate x:Key="LinkTemplate">
      <go:LinkPanel>
        <go:Link.Route>
          <go:Route Routing="Orthogonal" Corner="4"
                    FromEndSegmentLength="4" />
        </go:Link.Route>
        <go:LinkShape Stroke="Black"
                      StrokeThickness="1.5" />
        <Path Fill="Black"
              go:LinkPanel.ToArrow="Standard" />
      </go:LinkPanel>
    </DataTemplate>
  </UserControl.Resources>

  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="0" Orientation="Horizontal">
      <TextBlock Text="Spacing: " FontWeight="Bold" />
      <Slider x:Name="mySpaceSlider"
              Orientation="Horizontal" Width="150"
              Minimum="0.1" Maximum="5.0"
              Value="{Binding Path=Space, Mode=TwoWay,
                      Source={StaticResource myLengthConverter}}" />
      <TextBlock Text=" or use Control-mouse-wheel to zoom" />
    </StackPanel>
    <go:Diagram Grid.Row="1" x:Name="myDiagram"
                Padding="10 0 10 10"
                HorizontalContentAlignment="Stretch"
                VerticalContentAlignment="Stretch"
                NodeTemplateDictionary="{StaticResource DTD}"
                LinkTemplate="{StaticResource LinkTemplate}"
                IsReadOnly="True"
                GridVisible="True">
      <go:Diagram.GridPattern>
        <go:GridPattern>
          <Path Stroke="LightGray" StrokeThickness="1"
                go:GridPattern.Figure="VerticalLine" />
          <Path Stroke="Gray" StrokeThickness="1"
                go:GridPattern.Figure="VerticalLine"
                go:GridPattern.Interval="5" />
          <Path Stroke="LightGray" StrokeThickness="1"
                go:GridPattern.Figure="HorizontalLine"
                go:GridPattern.Interval="10" />
        </go:GridPattern>
      </go:Diagram.GridPattern>
      <!-- Intercept mouse wheel and keyboard zoom commands. -->
      <go:Diagram.CommandHandler>
        <local:SpaceZoomCommandHandler Conv="{StaticResource myLengthConverter}" />
      </go:Diagram.CommandHandler>
    </go:Diagram>
  </Grid>
</UserControl>
