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

<UserControl x:Class="Grouping.Grouping"
    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>
    <!-- show either a "+" or a "-" as the Button content -->
    <go:BooleanStringConverter x:Key="theButtonConverter" TrueString="-" FalseString="+" />

    <DataTemplate x:Key="NodeTemplate">
      <go:NodePanel Sizing="Auto" go:Part.SelectionAdorned="True">
        <go:NodeShape go:NodePanel.Figure="Ellipse" Fill="{Binding Path=Data.Color}" />
        <TextBlock Text="{Binding Path=Data.Color}" />
      </go:NodePanel>
    </DataTemplate>
    
    <DataTemplate x:Key="GroupTemplate">
      <Border CornerRadius="5" BorderThickness="2" Background="Transparent"
              BorderBrush="{Binding Path=Data.Color}"
              go:Part.SelectionAdorned="True"
              go:Node.LocationElementName="myGroupPanel"
              go:Group.IsSubGraphExpanded="False">
        <StackPanel>
          <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
            <Button x:Name="myCollapseExpandButton" Click="CollapseExpandButton_Click"
                Content="{Binding Path=Group.IsExpandedSubGraph, Converter={StaticResource theButtonConverter}}"
                Width="20" Margin="0 0 5 0" />
            <TextBlock Text="{Binding Path=Data.Key}" FontWeight="Bold" />
          </StackPanel>
          <go:GroupPanel x:Name="myGroupPanel" Padding="5" />
        </StackPanel>
        <go:Group.Layout>
          <go:LayeredDigraphLayout Direction="90" Conditions="Standard GroupSizeChanged" />
        </go:Group.Layout>
      </Border>
    </DataTemplate>
  </UserControl.Resources>

  <Grid>
    <go:Diagram x:Name="myDiagram" Padding="10"
                HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
                NodeTemplate="{StaticResource NodeTemplate}"
                GroupTemplate="{StaticResource GroupTemplate}">
      <go:Diagram.Layout>
        <go:ForceDirectedLayout Conditions="Standard GroupSizeChanged" />
      </go:Diagram.Layout>
    </go:Diagram>
  </Grid>
</UserControl>
