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

<Window x:Class="Basic.MainWindow"
    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:Basic"
    Title="GoWpf Basic" Width="800" Height="600">
  <FrameworkElement.Resources>
    <go:BooleanBrushConverter x:Key="theSelectionConverter"
                              FalseBrush="Transparent" TrueBrush="{x:Static SystemColors.HighlightBrush}" />

    <DataTemplate x:Key="MyNodeTemplate">
      <StackPanel go:Node.LocationElementName="Icon"
                  go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}"
                  go:Node.LocationSpot="Center">
        <TextBlock Text="{Binding Path=Data.Key, Mode=TwoWay}"
                   HorizontalAlignment="Center"
                   go:Part.TextEditable="True"/>
        <Grid HorizontalAlignment="Center">
          <!-- This shows as the highlight when selected. -->
          <Ellipse Fill="{x:Null}"
                   Stroke="{Binding Path=Part.IsSelected, Converter={StaticResource theSelectionConverter}}"
                   StrokeThickness="6"
                   Width="37" Height="37" />
          <Ellipse x:Name="Icon"
                   Fill="{Binding Path=Data.Color}"
                   Stroke="Gray" StrokeThickness="1"
                   Width="30" Height="30"
                   go:Node.PortId=""
                   go:Node.LinkableFrom="True" go:Node.LinkableTo="True"
                   Cursor="Hand" />
          <!-- Hide the center of the circle so it does not respond to link drawing gestures. -->
          <Ellipse Fill="Transparent"
                   Width="20" Height="20"/>
        </Grid>
        <ContextMenuService.ContextMenu>
          <ContextMenu>
            <MenuItem Header="a node command" Click="NodeMenuClick" />
            <MenuItem Command="Copy" />
            <MenuItem Command="Cut" />
            <MenuItem Command="Paste" />
            <MenuItem Command="Delete" />
            <MenuItem Command="Undo" />
            <MenuItem Command="Redo" />
          </ContextMenu>
        </ContextMenuService.ContextMenu>
      </StackPanel>
    </DataTemplate>

    <DataTemplate x:Key="MyLinkTemplate">
      <go:LinkPanel>
        <go:Link.Route>
          <!-- Make the relink handles bigger, to make them easier to grab. -->
          <go:Route RelinkableFrom="True" RelinkableTo="True">
            <go:Route.RelinkFromAdornmentTemplate>
              <DataTemplate>
                <go:LinkPanel>
                  <go:ToolHandle go:LinkPanel.Index="0" go:NodePanel.Figure="Diamond" Width="12" Height="12" Fill="Cyan" Stroke="Black" StrokeThickness="1" Cursor="Hand" />
                </go:LinkPanel>
              </DataTemplate>
            </go:Route.RelinkFromAdornmentTemplate>
            <go:Route.RelinkToAdornmentTemplate>
              <DataTemplate>
                <go:LinkPanel>
                  <go:ToolHandle go:LinkPanel.Index="-1" go:NodePanel.Figure="Diamond" Width="12" Height="12" Fill="Cyan" Stroke="Black" StrokeThickness="1" Cursor="Hand" />
                </go:LinkPanel>
              </DataTemplate>
            </go:Route.RelinkToAdornmentTemplate>
          </go:Route>
        </go:Link.Route>
        <!-- This thick LinkShape acts as the highlight when selected.
             Also, when not selected the thickness makes it easier to select the Link. -->
        <go:LinkShape Stroke="{Binding Path=Part.IsSelected, Converter={StaticResource theSelectionConverter}}"
                      StrokeThickness="6" />
        <go:LinkShape x:Name="Path" Stroke="Black" StrokeThickness="1" />
        <Path Fill="Black" go:LinkPanel.ToArrow="Standard" />
        <ContextMenuService.ContextMenu>
          <ContextMenu>
            <MenuItem Header="a link command" Click="LinkMenuClick" />
            <MenuItem Command="Copy" />
            <MenuItem Command="Cut" />
            <MenuItem Command="Paste" />
            <MenuItem Command="Delete" />
            <MenuItem Command="Undo" />
            <MenuItem Command="Redo" />
          </ContextMenu>
        </ContextMenuService.ContextMenu>
      </go:LinkPanel>
    </DataTemplate>
  </FrameworkElement.Resources>

  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="100" />
      <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition Height="*" />
      <RowDefinition Height="200" />
    </Grid.RowDefinitions>
    <go:Palette x:Name="myPalette" Grid.Column="0"
                Padding="10" BorderBrush="Gray" BorderThickness="1"
                HorizontalContentAlignment="Left"
                VerticalContentAlignment="Top"
                NodeTemplate="{StaticResource MyNodeTemplate}">
      <go:Diagram.Layout>
        <go:GridLayout CellSize="5 5" WrappingColumn="1" Sorting="Forward" />
      </go:Diagram.Layout>
    </go:Palette>
    <go:Diagram x:Name="myDiagram" Grid.Column="1"
                Padding="10" BorderBrush="Gray" BorderThickness="1"
                HorizontalContentAlignment="Stretch"
                VerticalContentAlignment="Stretch"
                InitialDiagramBoundsSpot="Center"
                InitialPanelSpot="Center"
                NodeTemplate="{StaticResource MyNodeTemplate}"
                LinkTemplate="{StaticResource MyLinkTemplate}">
      <go:Diagram.ClickCreatingTool>
        <go:ClickCreatingTool DoubleClick="True">
          <go:ClickCreatingTool.PrototypeData>
            <local:MyNodeData Color="Orange" />
          </go:ClickCreatingTool.PrototypeData>
        </go:ClickCreatingTool>
      </go:Diagram.ClickCreatingTool>
      <go:Diagram.CommandHandler>
        <go:CommandHandler>
          <go:CommandHandler.PrototypeGroup>
            <local:MyNodeData IsSubGraph="True" />
          </go:CommandHandler.PrototypeGroup>
        </go:CommandHandler>
      </go:Diagram.CommandHandler>
      <ContextMenuService.ContextMenu>
        <ContextMenu>
          <MenuItem Header="the default command" Click="BackgroundMenuClick" />
          <MenuItem Command="Paste" />
          <MenuItem Command="Undo" />
          <MenuItem Command="Redo" />
        </ContextMenu>
      </ContextMenuService.ContextMenu>
    </go:Diagram>
    <RichTextBox Grid.Row="1" Grid.ColumnSpan="2" IsEnabled="False">
      <FlowDocument>
        <Paragraph>
          Using the mouse and common keyboard commands, you can pan, select, move,
          copy, delete, and undo/redo.  Drag-and-drop from the Palette on the left
          into the main Diagram on the right.  In addition, you can:
        </Paragraph>
        <List>
          <ListItem>
            <Paragraph>
              Create new nodes by double-clicking in the background of the diagram.
            </Paragraph>
          </ListItem>
          <ListItem>
            <Paragraph>
              Edit text by selecting a node and then clicking on the text or pressing F2.
            </Paragraph>
          </ListItem>
          <ListItem>
            <Paragraph>
              Draw new links by dragging from the inner edge of a node's circular shape.
            </Paragraph>
          </ListItem>
          <ListItem>
            <Paragraph>
              Reconnect existing links by selecting a link and then dragging one of its
              diamond-shaped handles at either end of the link.
            </Paragraph>
          </ListItem>
          <ListItem>
            <Paragraph>
              Group nodes and links by selecting some nodes and links and then typing Ctrl-G.
            </Paragraph>
          </ListItem>
          <ListItem>
            <Paragraph>
              Ungroup an existing group by selecting it and then typing Ctrl-Shift-G.
            </Paragraph>
          </ListItem>
        </List>
      </FlowDocument>
    </RichTextBox>
  </Grid>
</Window>
