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

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

  <UserControl.Resources>
    <DataTemplate x:Key="nodeTemplate1">
      <StackPanel go:Part.SelectionAdorned="True"
                  go:Node.LocationElementName="ellipse" go:Node.LocationSpot="Center"
                  go:Part.Text="{Binding Path=Data.Key}">
        <Ellipse x:Name="ellipse"
                 Fill="{Binding Path=Data.Color}" Stroke="Black" StrokeThickness="1"
                 Width="{Binding Path=Data.Width}" Height="{Binding Path=Data.Height}"
                 go:Node.PortId="" />
        <TextBlock Text="{Binding Path=Data.Key}" HorizontalAlignment="Center" />
      </StackPanel>
    </DataTemplate>
  </UserControl.Resources>

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

    <Border Grid.Row="0" Background="AliceBlue" Margin="1" Padding="1"
            BorderBrush="Gray" BorderThickness="2" CornerRadius="2">
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0" Grid.ColumnSpan="2"
                   Text="Grid Layout Properties" FontWeight="Bold" />
        <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal">
          <TextBlock Text="WrappingColumn: " VerticalAlignment="Center" />
          <TextBox x:Name="WrappingColumnTextBox" Text="0" />
        </StackPanel>
        <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
          <TextBlock Text="WrappingWidth: " VerticalAlignment="Center" />
          <TextBox x:Name="WrappingWidthTextBox" Text="NaN" />
        </StackPanel>
        <StackPanel Grid.Row="2" Grid.Column="0" Orientation="Horizontal">
          <TextBlock Text="CellSize: " VerticalAlignment="Center" />
          <TextBox x:Name="CellSizeTextBox" Text="NaN NaN" />
        </StackPanel>
        <StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal">
          <TextBlock Text="Spacing: " VerticalAlignment="Center" />
          <TextBox x:Name="SpacingTextBox" Text="10 10" />
        </StackPanel>
        <StackPanel Grid.Row="3" Grid.ColumnSpan="2" Orientation="Horizontal">
          <TextBlock Text="Alignment: " VerticalAlignment="Center" />
          <StackPanel x:Name="AlignmentRadioButtonGroup" Tag="Location"
                      Orientation="Horizontal">
            <RadioButton Content="Position" Checked="RadioButton_Checked" />
            <RadioButton Content="Location" Checked="RadioButton_Checked" IsChecked="True" />
          </StackPanel>
        </StackPanel>
        <StackPanel Grid.Row="4" Grid.ColumnSpan="2" Orientation="Horizontal">
          <TextBlock Text="Arrangement: " VerticalAlignment="Center" />
          <StackPanel x:Name="ArrangementRadioButtonGroup" Tag="LeftToRight"
                      Orientation="Horizontal">
            <RadioButton Content="LeftToRight" Checked="RadioButton_Checked" IsChecked="True" />
            <RadioButton Content="RightToLeft" Checked="RadioButton_Checked" />
          </StackPanel>
        </StackPanel>
        <StackPanel Grid.Row="5" Grid.ColumnSpan="2" Orientation="Horizontal">
          <TextBlock Text="Sorting: " VerticalAlignment="Center" />
          <StackPanel x:Name="SortingRadioButtonGroup" Tag="Ascending"
                      Orientation="Horizontal">
            <RadioButton Content="Forward" Checked="RadioButton_Checked" />
            <RadioButton Content="Reverse" Checked="RadioButton_Checked" />
            <RadioButton Content="Ascending" Checked="RadioButton_Checked" IsChecked="True" />
            <RadioButton Content="Descending" Checked="RadioButton_Checked" />
          </StackPanel>
        </StackPanel>
      </Grid>
    </Border>

    <go:Diagram x:Name="myDiagram" Grid.Row="1"
                HorizontalContentAlignment="Center"
                VerticalContentAlignment="Top"
                NodeTemplate="{StaticResource nodeTemplate1}">
      <go:Diagram.Layout>
        <go:GridLayout Conditions="Standard ViewportSizeChanged"
            WrappingWidth="{Binding ElementName=WrappingWidthTextBox, Path=Text}"
            WrappingColumn="{Binding ElementName=WrappingColumnTextBox, Path=Text}"
            CellSize="{Binding ElementName=CellSizeTextBox, Path=Text}"
            Spacing="{Binding ElementName=SpacingTextBox, Path=Text}"
            Alignment="{Binding ElementName=AlignmentRadioButtonGroup, Path=Tag}"
            Arrangement="{Binding ElementName=ArrangementRadioButtonGroup, Path=Tag}"
            Sorting="{Binding ElementName=SortingRadioButtonGroup, Path=Tag}"
          />
      </go:Diagram.Layout>
    </go:Diagram>
  </Grid>
</UserControl>
