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

<UserControl x:Class="DecisionTree.DecisionTree"
    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>
    <go:DataTemplateDictionary x:Key="NodeTemplates">
      <!-- This node template shows decision nodes, including two buttons that
         expand to further decision nodes for that choice -->
      <DataTemplate x:Key="DecisionNode">
        <!-- nodes are initially not visible -->
        <go:NodePanel Sizing="Auto" go:Part.Visible="False">
          <!-- node shape surrounds the text and buttons -->
          <go:NodeShape go:NodePanel.Figure="Cloud" Fill="WhiteSmoke" Stroke="Black" />
          <!-- Abbreviated text plus two choice buttons -->
          <StackPanel Orientation="Horizontal">
            <TextBlock Margin="5" HorizontalAlignment="Center" FontSize="26"
                     Text="{Binding Path=Data.Key}" />
            <StackPanel Orientation="Vertical">
              <!-- each button is data-bound to the Info data;
                 clicking expands or collapses that choice -->
              <Button MinWidth="50" Click="Button_Click"
                    go:Node.PortId="{Binding Path=Data.A}"
                    Content="{Binding Path=Data.AText}" FontWeight="Bold">
                <!-- each button has a tooltip to provide further information -->
                <ToolTipService.ToolTip>
                  <TextBlock Text="{Binding Path=Data.AToolTip}"
                           TextWrapping="Wrap" MaxWidth="300" />
                </ToolTipService.ToolTip>
              </Button>
              <Button MinWidth="50" Click="Button_Click"
                    go:Node.PortId="{Binding Path=Data.B}"
                    Content="{Binding Path=Data.BText}" FontWeight="Bold">
                <ToolTipService.ToolTip>
                  <TextBlock Text="{Binding Path=Data.BToolTip}"
                           TextWrapping="Wrap" MaxWidth="300" />
                </ToolTipService.ToolTip>
              </Button>
            </StackPanel>
          </StackPanel>
        </go:NodePanel>
      </DataTemplate>

      <!-- this template displays the "leaf" nodes: personality descriptions -->
      <DataTemplate x:Key="PersonalityNode">
        <Border BorderBrush="Black" BorderThickness="1"
              Padding="5" CornerRadius="5" go:Part.Visible="False">
          <TextBlock Text="{Binding Path=Data.Text}" TextWrapping="Wrap" MaxWidth="500" />
        </Border>
      </DataTemplate>
    </go:DataTemplateDictionary>

    <DataTemplate x:Key="LinkTemplate">
      <!-- links are initially not visible, but are made visible as the tree is expanded -->
      <go:LinkShape Stroke="Red" StrokeThickness="1"
                    go:Link.Selectable="False" go:Part.Visible="False" />
    </DataTemplate>
  </UserControl.Resources>

  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <TextBlock Grid.Row="0" HorizontalAlignment="Center" Margin="5"
               Text="Explore various personality traits" FontSize="16" />
    <go:Diagram Grid.Row="1" x:Name="myDiagram" Padding="10"
                HorizontalContentAlignment="Left" VerticalContentAlignment="Stretch"
                NodeTemplateDictionary="{StaticResource NodeTemplates}"
                LinkTemplate="{StaticResource LinkTemplate}"
                Loaded="myDiagram_Loaded">
      <go:Diagram.Layout>
        <go:TreeLayout Conditions="Standard VisibleChanged" />
      </go:Diagram.Layout>
    </go:Diagram>
  </Grid>
</UserControl>
