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

<UserControl x:Class="UpdateDemo.UpdateDemo"
    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>
    <DataTemplate x:Key="NodeTemplate">
      <go:NodePanel Sizing="Auto"
                    go:Part.SelectionAdorned="True"
                    go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}">
        <go:NodeShape go:NodePanel.Figure="Pentagon"
                      Fill="LightBlue" Stroke="Black" StrokeThickness="1"
                      go:Node.PortId=""
                      go:Node.LinkableFrom="True" go:Node.LinkableTo="True" />
        <TextBlock Text="{Binding Path=Data.Key}" Margin="10"
                   HorizontalAlignment="Center" VerticalAlignment="Center" />
      </go:NodePanel>
    </DataTemplate>
    
    <DataTemplate x:Key="NodeTemplate2">
      <StackPanel go:Part.SelectionAdorned="True"
                  go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}">
        <Ellipse Fill="LightGreen" Width="30" Height="30"
                 go:Node.PortId=""
                 go:Node.LinkableFrom="True" go:Node.LinkableTo="True" />
        <TextBlock Text="{Binding Path=Data.Key}" Foreground="Green"
                   HorizontalAlignment="Center" />
      </StackPanel>
    </DataTemplate>

    <DataTemplate x:Key="LinkTemplate">
      <go:LinkPanel go:Part.SelectionElementName="Path" go:Part.SelectionAdorned="True">
        <go:Link.Route>
          <go:Route RelinkableFrom="True" RelinkableTo="True" />
        </go:Link.Route>
        <go:LinkShape x:Name="Path" Stroke="Black" StrokeThickness="1" />
        <Path Stroke="Black" StrokeThickness="1" go:LinkPanel.ToArrow="Standard" />
        <TextBlock Text="{Binding Path=Data.Text, Mode=TwoWay}"
                   FontSize="9" go:Part.TextEditable="True" />
      </go:LinkPanel>
    </DataTemplate>

    <DataTemplate x:Key="LinkTemplate2">
      <go:LinkPanel go:Part.SelectionElementName="Path" go:Part.SelectionAdorned="True">
        <go:Link.Route>
          <go:Route RelinkableFrom="True" RelinkableTo="True" Curve="Bezier" />
        </go:Link.Route>
        <go:LinkShape x:Name="Path" Stroke="Green"
                      StrokeThickness="2" StrokeDashArray="2 2" />
        <!-- implement a custom arrowhead using an Ellipse -->
        <Ellipse Fill="Green" Width="8" Height="8" go:LinkPanel.Alignment="1 0.5"
                 go:LinkPanel.Index="-1" go:LinkPanel.Orientation="Along" />
      </go:LinkPanel>
    </DataTemplate>
  </UserControl.Resources>

  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*" />
      <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid Grid.Column="0">
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
      </Grid.RowDefinitions>
      <TextBlock Text="You can move/copy/paste/delete selected parts, create new nodes by background double-clicking, draw new links or reconnect existing links, edit link text, and undo/redo."
                 Grid.Row="0" TextWrapping="Wrap" />
      <go:Diagram Grid.Row="1" x:Name="myDiagram" Padding="10"
                  BorderBrush="Blue" BorderThickness="1"
                  HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
                  NodeTemplate="{StaticResource NodeTemplate}"
                  LinkTemplate="{StaticResource LinkTemplate}" />
      <go:Diagram Grid.Row="2" x:Name="myDiagram2" Padding="10"
                  BorderBrush="Green" BorderThickness="1"
                  HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
                  NodeTemplate="{StaticResource NodeTemplate2}"
                  LinkTemplate="{StaticResource LinkTemplate2}" />
    </Grid>
    <Grid Grid.Column="1">
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>
      <StackPanel Grid.Row="0" Orientation="Horizontal">
        <TextBlock Text="Model.Changed log:" FontWeight="Bold" Margin="0 0 5 0" />
        <Button Content="Clear Log" Click="ClearLog" />
      </StackPanel>
      <StackPanel Grid.Row="1" Orientation="Horizontal">
        <CheckBox x:Name="ShowChanges" Content="Show New Changes" IsChecked="True" />
        <CheckBox x:Name="ShowLayouts" Content="Show New Layouts" IsChecked="False" />
      </StackPanel>
      <Border Grid.Row="2" BorderBrush="Black" BorderThickness="1" Padding="2">
        <ScrollViewer x:Name="myScroller" HorizontalScrollBarVisibility="Auto">
          <TextBlock x:Name="myLog" />
        </ScrollViewer>
      </Border>
      <StackPanel Grid.Row="3" Orientation="Horizontal">
        <TextBlock Text="Undo Manager state:" FontWeight="Bold" />
      </StackPanel>
      <TreeView Grid.Row="4" x:Name="myTreeView" Background="Transparent" />
      <StackPanel Grid.Row="5" Orientation="Horizontal">
        <Button Content="Undo"
                Command="{Binding ElementName=myDiagram, Path=CommandHandler.UndoCommand}" />
        <Button Content="Redo"
                Command="{Binding ElementName=myDiagram, Path=CommandHandler.RedoCommand}" />
        <TextBlock Text=" (an undo/redo selects the next transaction to redo)" />
      </StackPanel>
    </Grid>
  </Grid>
</UserControl>
