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

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

  <UserControl.Resources>
    <!-- A custom adornment template that makes the border red-->
    <DataTemplate x:Key="BoxNodeAdornmentTemplate">
      <go:SelectionHandle Stroke="Red" StrokeThickness="3" go:Part.Selectable="False" />
    </DataTemplate>

    <!-- A link with no arrowhead -->
    <DataTemplate x:Key="SimpleLinkTemplate">
      <go:LinkShape Stroke="{Binding Path=Link.ToData.LinkColor}" StrokeThickness="2">
        <go:Link.Route>
          <go:Route ToShortLength="-2" FromShortLength="-2" Curve="Bezier" go:Part.Selectable="False" />
        </go:Link.Route>
      </go:LinkShape>
    </DataTemplate>

    <!-- When a node is selected this Button appears. A user can also right-click on nodes. -->
    <DataTemplate x:Key="StateSelectionTemplate">
      <go:SpotPanel>
        <Button Click="CreateChild"
                go:SpotPanel.Spot="TopRight" go:SpotPanel.Alignment="Center">
          <go:NodePanel>
            <go:NodeShape go:NodePanel.Figure="ThickCross" Width="8" Height="8"
                  Fill="Yellow" Stroke="Black" StrokeThickness="1" />
          </go:NodePanel>
        </Button>
      </go:SpotPanel>
    </DataTemplate>

    <go:DataTemplateDictionary x:Key="NodeTemplateDictionary">
      <!-- the default template -->
      <DataTemplate x:Key="">
        <!-- go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}" -->
        <StackPanel Orientation="Vertical"  go:Part.Copyable="False"
                  
                  go:Part.LayoutId="{Binding Path=Data.LayoutId}"
                  go:Part.SelectionAdorned="True"         
                  go:Part.SelectionAdornmentTemplate="{StaticResource StateSelectionTemplate}"
                  MinWidth="90">
          <go:NodePanel Sizing="Auto">
            <go:NodeShape go:NodePanel.Figure="{Binding Path=Data.Figure}" />
            <!-- Since we have a single-click text edit in this sample, a margin on 
            the left and right of the text block allow for some selection space -->
            <TextBlock go:Part.TextEditable="True"
                       Text="{Binding Path=Data.Text, Mode=TwoWay}"
                       MinWidth="30" MinHeight="15" Margin="10 0 10 0" />
          </go:NodePanel>
          <Line Stroke="{Binding Path=Data.LinkColor}" StrokeThickness="2"
              X1="0" Y1="0" X2="1" Y2="0"
              Stretch="Fill" go:Node.PortId="" 
              go:Node.FromSpot="{Binding Path=Data.FromSpot}"
              go:Node.ToSpot="{Binding Path=Data.ToSpot}" />
        </StackPanel>
      </DataTemplate>

      <DataTemplate x:Key="Root">
        <StackPanel Orientation="Vertical" go:Part.SelectionAdorned="True" go:Part.Copyable="False"
                  go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}"
                  go:Part.LayoutId="None" go:Part.Deletable="False">
          <go:NodePanel Sizing="Auto">
            <go:NodeShape go:NodePanel.Figure="Ellipse"  Fill="LightBlue" />
            <TextBlock Text="{Binding Path=Data.Text, Mode=TwoWay}" go:Part.TextEditable="True" />
          </go:NodePanel>
        </StackPanel>
      </DataTemplate>

      <!-- Note and Title have their own templates -->
      <DataTemplate x:Key="Note">
        <Border Background="LightYellow" BorderBrush="Gray" BorderThickness="1"
              go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}"
              go:Part.SelectionAdorned="True"
              go:Part.SelectionAdornmentTemplate="{StaticResource BoxNodeAdornmentTemplate}">
          <TextBlock Text="{Binding Path=Data.Text, Mode=TwoWay}" FontSize="12"
                   Margin="2" TextWrapping="Wrap"
                   go:Part.TextEditable="True" />
        </Border>
      </DataTemplate>

      <DataTemplate x:Key="Title">
        <TextBlock Text="{Binding Path=Data.Text, Mode=TwoWay}" FontSize="16" FontWeight="Bold"
                 TextWrapping="Wrap"
                 go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}"
                 go:Part.SelectionAdorned="True"
                 go:Part.SelectionAdornmentTemplate="{StaticResource BoxNodeAdornmentTemplate}"
                 go:Part.TextEditable="True" />
      </DataTemplate>
    </go:DataTemplateDictionary>

  </UserControl.Resources>

  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <StackPanel Margin="1" Grid.Row="0" Orientation="Horizontal">
      <!-- contains helpful text -->
      <Border x:Name="notePanel" Background="AliceBlue" BorderBrush="Gray"
              BorderThickness="2" CornerRadius="2" Margin="1" Padding="1">
        <StackPanel Margin="1">
          <TextBlock HorizontalAlignment="Center" Text="Mind Map Options" />
          <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Width="125">
            Double click to create a new branch.
            Right click a node to add a leaf onto it.
            Drag Notes and Titles from the box to the right.
          </TextBlock>
        </StackPanel>
      </Border>

      <!-- contains elements to place on the page, like a Note -->
      <go:Palette x:Name="nodePalette" Grid.Row="1"
                  Width="125" Height="Auto" Padding="5" Margin="2" BorderBrush="Black" BorderThickness="1" 
                  Background="White" MaximumSelectionCount="1"
                  NodeTemplateDictionary="{StaticResource NodeTemplateDictionary}">
        <go:Palette.Layout>
          <go:GridLayout WrappingColumn="1" CellSize="25 25" Sorting="Forward" />
        </go:Palette.Layout>
      </go:Palette>

      <StackPanel Height="Auto">
        <!-- printPanel contains all printing controls -->
        <Border x:Name="printPanel" Background="AliceBlue" BorderBrush="Gray"
              BorderThickness="2" CornerRadius="2" Margin="1" Padding="1">
          <StackPanel Margin="1">
            <TextBlock HorizontalAlignment="Center" Text="Printing Options" />
            <StackPanel Orientation="Horizontal">
              <TextBlock VerticalAlignment="Center" Text="Scale: " />
              <TextBox x:Name="printScale" Text="{Binding Path=PrintManager.Scale, ElementName=myDiagram, Mode=TwoWay}" />
            </StackPanel>
            <Button x:Name="printButton" HorizontalAlignment="Left" Content="Print"  />
          </StackPanel>
        </Border>

        <!-- contains save and load -->
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="0 4 0 0">
          <Button Content="Save" Click="Save_Click" />
          <Button Content="Load" Click="Load_Click" x:Name="LoadButton" IsEnabled="False" />
          <Button Content="Layout" Click="Layout_Click" />
        </StackPanel>

      </StackPanel>

    </StackPanel>

    <go:Diagram x:Name="myDiagram" Grid.Row="1" Margin="2" Padding="5"
                BorderBrush="Black" BorderThickness="1"
                HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
                InitialStretch="Uniform"
                NodeTemplateDictionary="{StaticResource NodeTemplateDictionary}"
                LinkTemplate="{StaticResource SimpleLinkTemplate}">

      <go:Diagram.Layout>
        <go:MultiLayout>
          <go:TreeLayout x:Name="RightLayout" Id="Right" Angle="0"
                               Arrangement="FixedRoots"  SetsPortSpot="False" SetsChildPortSpot="False" LayerSpacing="25" />
          <go:TreeLayout x:Name="LeftLayout" Id="Left" Angle="180"
                               Arrangement="FixedRoots"  SetsPortSpot="False" SetsChildPortSpot="False" LayerSpacing="25" />
        </go:MultiLayout>
      </go:Diagram.Layout>

      <go:Diagram.DraggingTool>
        <go:DraggingTool Inclusions="SubTree" />
      </go:Diagram.DraggingTool>

      <go:Diagram.TextEditingTool>
        <go:TextEditingTool Starting="SingleClick" />
      </go:Diagram.TextEditingTool>

      <go:Diagram.CommandHandler>
        <go:CommandHandler DeletingInclusions="SubTree" />
      </go:Diagram.CommandHandler>
    </go:Diagram>
  </Grid>
</UserControl>