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

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

  <FrameworkElement.Resources>
    <DataTemplate x:Key="NodeTemplate">
      <go:NodePanel Sizing="Fixed"
                    go:Part.SelectionAdorned="True"
                    go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}"
                    go:Node.LocationSpot="Center">
        <go:NodeShape go:NodePanel.Figure="RoundedRectangle"
                      Width="{Binding Path=Data.Width}"
                      Height="{Binding Path=Data.Height}"
                      Fill="{Binding Path=Data.Color}" Stroke="Black" StrokeThickness="1" />
        <TextBlock Text="{Binding Path=Data.Key}" Foreground="Black"
                   HorizontalAlignment="Center" VerticalAlignment="Center" />
      </go:NodePanel>
    </DataTemplate>
  </FrameworkElement.Resources>

  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="0" Orientation="Horizontal">
      <TextBlock x:Name="myStatus" />
    </StackPanel>
    <go:Diagram Grid.Row="1" x:Name="myDiagram" Padding="10"
                HorizontalContentAlignment="Stretch"
                VerticalContentAlignment="Stretch"
                InitialStretch="UniformToFill"
                NodeTemplate="{StaticResource NodeTemplate}">
      <!-- custom PartManager -->
      <go:Diagram.PartManager>
        <local:VirtualizingPartManager />
      </go:Diagram.PartManager>
      <!-- custom DiagramPanel -->
      <go:Diagram.Template>
        <ControlTemplate TargetType="go:Diagram">
          <Border x:Name="Border"
            Background="{TemplateBinding Background}"
            BorderBrush="{TemplateBinding BorderBrush}"
            BorderThickness="{TemplateBinding BorderThickness}">
            <ScrollViewer HorizontalScrollBarVisibility="Auto"
                          VerticalScrollBarVisibility="Auto"
                          CanContentScroll="True">
              <local:VirtualizingDiagramPanel x:Name="Panel"
                         Stretch="{TemplateBinding Stretch}"
                         Padding="{TemplateBinding Padding}"
                         HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                         VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
            </ScrollViewer>
          </Border>
        </ControlTemplate>
      </go:Diagram.Template>
      <!-- custom TreeLayout -->
      <go:Diagram.Layout>
        <local:VirtualizingTreeLayout NodeSpacing="10" />
      </go:Diagram.Layout>
      <!-- this status part is removed after the data has been loaded -->
      <go:Node Id="Loading">
        <TextBlock Text="Loading..." Foreground="Red"
                   go:Node.Location="20 20" />
      </go:Node>
    </go:Diagram>
  </Grid>
</UserControl>