private void GenerateStickyHeaders( ICustomItemContainerGenerator generator, bool measureInvalidated, ref UIElement focusedElement )
    {
      CustomItemContainerGenerator customGenerator = ( CustomItemContainerGenerator )generator;

      if( !this.AreHeadersStickyCache && !this.AreGroupHeadersStickyCache && !this.AreParentRowsStickyCache )
      {
        this.RecycleUnusedStickyContainers( generator, m_stickyHeaders, null, ref focusedElement );
        m_stickyHeaders.Clear();
        return;
      }

      int numberOfContainerChecked = 0;

      StickyContainerInfoList newStickyHeaders = new StickyContainerInfoList();

      foreach( LayoutedContainerInfo layoutedContainerInfo in m_layoutedContainers )
      {
        UIElement container = layoutedContainerInfo.Container;

        // For each visible container, we must find what headers should be sticky for it.
        List<StickyContainerGenerated> stickyHeaders =
          customGenerator.GenerateStickyHeaders( container, this.AreHeadersStickyCache, this.AreGroupHeadersStickyCache, this.AreParentRowsStickyCache );

        stickyHeaders.Sort( StickyContainerGeneratedComparer.Singleton );

        // For each sticky headers returned, we must get the index of the last container
        // that could need that container to be sticky. 
        foreach( StickyContainerGenerated stickyHeaderInfo in stickyHeaders )
        {
          UIElement stickyContainer = ( UIElement )stickyHeaderInfo.StickyContainer;

          if( newStickyHeaders.ContainsContainer( stickyContainer ) )
            continue;

          int lastContainerIndex = customGenerator.GetLastHoldingContainerIndexForStickyHeader( stickyContainer );

          StickyContainerInfo stickyContainerInfo = new StickyContainerInfo( stickyContainer, stickyHeaderInfo.Index, lastContainerIndex );
          newStickyHeaders.Add( stickyContainerInfo );

          if( focusedElement == stickyContainer )
          {
            focusedElement = null;
          }

          this.HandleGeneratedStickyContainerPreparation( stickyHeaderInfo, measureInvalidated );
        }

        // We only need to find the sticky headers for one 
        // more element than what is already sticky.
        int visibleStickyHeadersCount = ( int )Math.Ceiling( this.GetStickyHeadersRegionHeight( newStickyHeaders ) / m_containerHeight );

        if( ( ++numberOfContainerChecked - visibleStickyHeadersCount ) >= 1 )
          break;
      }

      foreach( StickyContainerInfo stickyHeaderInfo in newStickyHeaders )
      {
        UIElement container = stickyHeaderInfo.Container;
        int index = m_layoutedContainers.IndexOfContainer( container );

        if( index > -1 )
        {
          m_layoutedContainers.RemoveAt( index );
        }

        m_layoutedContainersToRecycle.Remove( container );
      }

      this.RecycleUnusedStickyContainers( generator, m_stickyHeaders, newStickyHeaders, ref focusedElement );

      m_stickyHeaders.Clear();
      m_stickyHeaders.AddRange( newStickyHeaders );
      m_stickyHeaders.Sort( StickyContainerInfoComparer.Singleton );
    }
    private void GenerateContainers(
      ICustomItemContainerGenerator generator,
      int pageStartIndex,
      int pageEndIndex,
      bool measureInvalidated,
      ref UIElement focusedElement )
    {
      HashSet<UIElement> unusedLayoutedContainers = new HashSet<UIElement>( m_layoutedContainers.Select( item => item.Container ) );
      m_layoutedContainers.Clear();

      ScrollDirection scrollDirection = this.AnimatedScrollInfo.VerticalScrollingDirection;

      GeneratorPosition position;
      GeneratorDirection direction;
      int currentIndex;
      int step;

      if( ( scrollDirection == ScrollDirection.Forward )
        || ( scrollDirection == ScrollDirection.None ) )
      {
        position = generator.GeneratorPositionFromIndex( pageStartIndex );
        direction = GeneratorDirection.Forward;
        currentIndex = pageStartIndex;
        step = 1;
      }
      else
      {
        position = generator.GeneratorPositionFromIndex( pageEndIndex );
        direction = GeneratorDirection.Backward;
        currentIndex = pageEndIndex;
        step = -1;
      }

      using( generator.StartAt( position, direction, true ) )
      {
        while( ( currentIndex >= pageStartIndex ) && ( currentIndex <= pageEndIndex ) )
        {
          UIElement container = this.GenerateContainer( generator, currentIndex, measureInvalidated, true );
          if( container == null )
            break;

          if( focusedElement == container )
          {
            focusedElement = null;
          }

          // The container is now part of the page layout. Add it to the list.
          m_layoutedContainers.Add( new LayoutedContainerInfo( currentIndex, container ) );
          m_layoutedContainersToRecycle.Remove( container );
          unusedLayoutedContainers.Remove( container );

          currentIndex += step;
        }
      }

      // A ScrollViewer may measure forever if the containers that are "underneath" the horizontal
      // scrollbar are the ones that required the scrollbar in the first place.
      if( m_lastVisiblePageIndexes != PageIndexes.Empty )
      {
        int remainingItemCount = ( m_lastVisiblePageIndexes.EndIndex - m_lastVisiblePageIndexes.StartIndex )
                               - ( pageEndIndex - pageStartIndex );

        if( ( remainingItemCount > 0 ) && ( this.GetMaxDesiredWidth() < this.AnimatedScrollInfo.ExtentWidth ) )
        {
          int itemCount = generator.ItemCount;

          if( ( currentIndex >= 0 ) && ( currentIndex < itemCount ) )
          {
            position = generator.GeneratorPositionFromIndex( currentIndex );

            using( generator.StartAt( position, direction, true ) )
            {
              while( ( remainingItemCount > 0 ) && ( currentIndex >= 0 ) && ( currentIndex < itemCount ) )
              {
                UIElement container = this.GenerateContainer( generator, currentIndex, measureInvalidated, true );
                if( container == null )
                  break;

                if( focusedElement == container )
                {
                  focusedElement = null;
                }

                // The container is now part of the page layout. Add it to the list.
                m_layoutedContainers.Add( new LayoutedContainerInfo( currentIndex, container ) );
                m_layoutedContainersToRecycle.Remove( container );
                unusedLayoutedContainers.Remove( container );

                currentIndex += step;
                remainingItemCount--;
              }
            }
          }
        }
      }

      m_layoutedContainers.Sort();

      // Recycle the containers that have not been reused in the current page.
      foreach( var container in unusedLayoutedContainers )
      {
        // We do not recycle the focused element!
        if( container.IsKeyboardFocusWithin )
        {
          Debug.Assert( focusedElement == null );
          focusedElement = container;
        }
        else
        {
          int index = generator.GetRealizedIndexForContainer( container );

          this.RecycleContainer( generator, index, container );

          m_layoutedContainersToRecycle.Add( container );
        }
      }
    }
    private void GenerateFocusedContainer(
      ICustomItemContainerGenerator generator,
      bool measureInvalidated,
      UIElement focusedElement )
    {
      if( focusedElement == null )
        return;

      int index = generator.GetRealizedIndexForContainer( focusedElement );

      if( index >= 0 )
      {
        if( measureInvalidated )
        {
          this.MeasureContainer( focusedElement );
        }

        m_layoutedContainers.Add( new LayoutedContainerInfo( index, focusedElement ) );
      }
      else
      {
        this.RecycleContainer( focusedElement );
      }
    }
    private void RecycleUnusedStickyContainers(
      ICustomItemContainerGenerator generator,
      StickyContainerInfoList stickyContainers,
      StickyContainerInfoList stickyContainersToExclude,
      ref UIElement focusedElement )
    {
      for( int i = stickyContainers.Count - 1; i >= 0; i-- )
      {
        StickyContainerInfo stickyHeaderInfo = stickyContainers[ i ];
        UIElement container = stickyHeaderInfo.Container;

        if( m_layoutedContainers.ContainsContainer( container ) )
          continue;

        if( ( stickyContainersToExclude != null ) && ( stickyContainersToExclude.ContainsContainer( container ) ) )
          continue;

        if( container.IsKeyboardFocusWithin )
        {
          Debug.Assert( ( focusedElement == null ) || ( focusedElement == container ) );
          focusedElement = container;
          continue;
        }

        int index = generator.GetRealizedIndexForContainer( container );

        this.RecycleContainer( generator, index, container );
        stickyContainers.RemoveAt( i );
      }
    }
    private void RecycleContainer( ICustomItemContainerGenerator generator, int containerIndex, UIElement container )
    {
      if( ( generator != null ) && ( containerIndex != -1 ) )
      {
        try
        {
          GeneratorPosition position = generator.GeneratorPositionFromIndex( containerIndex );
          generator.Remove( position, 1 );
        }
        catch
        {
          Debug.Fail( "Unable to remove container for containerIndex " + containerIndex );
        }
      }

#if DEBUG
      TableflowViewItemsHost.SetRealizedIndex( container, -1 );
#endif //DEBUG
      TableflowViewItemsHost.ClearIsSticky( container );
      container.ClearValue( UIElement.ClipProperty );

      this.DisableElementNavigation( container );
      this.FreeRowSelector( container );

      m_layoutedContainersToRecycle.Add( container );
    }
    private void GenerateContainers(
      ICustomItemContainerGenerator generator,
      int pageStartIndex,
      int pageEndIndex,
      bool measureInvalidated,
      ref UIElement focusedElement )
    {
      ScrollDirection scrollDirection = this.AnimatedScrollInfo.VerticalScrollingDirection;

      GeneratorPosition position;
      GeneratorDirection direction;

      if( ( scrollDirection == ScrollDirection.Forward )
        || ( scrollDirection == ScrollDirection.None ) )
      {
        position = generator.GeneratorPositionFromIndex( pageStartIndex );
        direction = GeneratorDirection.Forward;
      }
      else
      {
        position = generator.GeneratorPositionFromIndex( pageEndIndex );
        direction = GeneratorDirection.Backward;
      }

      using( generator.StartAt( position, direction, true ) )
      {
        int currentIndex = ( direction == GeneratorDirection.Forward )
          ? pageStartIndex
          : pageEndIndex;

        while( ( direction == GeneratorDirection.Forward )
          ? ( currentIndex <= pageEndIndex )
          : ( currentIndex >= pageStartIndex ) )
        {
          UIElement container = this.GenerateContainer( generator, currentIndex, measureInvalidated, true );

          if( container == null )
            return;

          if( ( focusedElement != null ) && ( focusedElement == container ) )
          {
            focusedElement = null;
          }

          // The container is now part of the page layout. Add it to the list.
          m_layoutedContainers.Add( new LayoutedContainerInfo( currentIndex, container ) );
          m_layoutedContainersToRecycle.Remove( container );

          currentIndex += ( direction == GeneratorDirection.Forward ) ? 1 : -1;
        }
      }

      m_layoutedContainers.Sort();
    }
    private UIElement RecycleSafeContainers(
      ICustomItemContainerGenerator generator,
      int pageStartIndex,
      int pageEndIndex )
    {
      if( m_lastVisiblePageIndexes == PageIndexes.Empty )
        return this.RecycleContainers( generator, pageStartIndex, pageEndIndex );

      if( m_lastVisiblePageIndexes.StartIndex == pageStartIndex )
        return this.RecycleContainers( generator,
                                       pageStartIndex,
                                       Math.Max( pageEndIndex, m_lastVisiblePageIndexes.EndIndex ) );

      if( m_lastVisiblePageIndexes.EndIndex == pageEndIndex )
        return this.RecycleContainers( generator,
                                       Math.Min( pageStartIndex, m_lastVisiblePageIndexes.StartIndex ),
                                       pageEndIndex );

      int itemCount = generator.ItemCount;
      int threshold = Math.Max( 0,
                                ( m_lastVisiblePageIndexes.EndIndex - m_lastVisiblePageIndexes.StartIndex ) -
                                ( pageEndIndex - pageStartIndex ) );

      int endIndex = Math.Min( pageEndIndex + threshold, itemCount - 1 );
      if( endIndex < 0 )
        return this.RecycleAllContainers( generator );

      int startIndex = Math.Max( endIndex - threshold - ( pageEndIndex - pageStartIndex ), 0 );

      return this.RecycleContainers( generator, startIndex, endIndex );
    }
    private UIElement GenerateContainer( ICustomItemContainerGenerator generator, int index, bool forceMeasure )
    {
      bool isNewlyRealized;
      var container = ( UIElement )generator.GenerateNext( out isNewlyRealized );
      if( container == null )
        return null;

      if( isNewlyRealized )
      {
        var collection = this.Children;
        if( !collection.Contains( container ) )
        {
          collection.Add( container );
        }

        this.EnableElementNavigation( container );
        KeyboardNavigation.SetTabIndex( container, index );
        this.PrepareContainer( container );
        this.MeasureContainer( container );
      }
      else if( forceMeasure )
      {
        this.MeasureContainer( container );
      }

      return container;
    }
    private UIElement RecycleContainers(
      ICustomItemContainerGenerator generator,
      int pageStartIndex,
      int pageEndIndex )
    {
      UIElement focusedElement = null;

      for( int i = m_layoutedContainers.Count - 1; i >= 0; i-- )
      {
        var container = m_layoutedContainers[ i ].Container;

        int index = generator.GetRealizedIndexForContainer( container );

        // If the container's index is now out of view, recycle that container.
        if( ( index < pageStartIndex ) || ( index > pageEndIndex ) )
        {
          // We do not recycle the focused element!
          if( container.IsKeyboardFocusWithin )
          {
            focusedElement = container;
          }
          else
          {
            this.RecycleContainer( generator, index, container );
          }

          m_layoutedContainers.RemoveAt( i );
        }
      }

      return focusedElement;
    }
Exemplo n.º 10
0
    private void GenerateContainers(
      ICustomItemContainerGenerator generator,
      double pageHeight,
      HashSet<UIElement> layoutedContainersToRecycle,
      bool measureInvalidated,
      ref PageIndexes pageIndexes,
      out double containersHeight )
    {
      int currentIndex = pageIndexes.StartIndex;
      GeneratorDirection direction;

      if( currentIndex == -1 )
      {
        currentIndex = pageIndexes.EndIndex;
        Debug.Assert( currentIndex != -1 );
        direction = GeneratorDirection.Backward;
      }
      else
      {
        direction = GeneratorDirection.Forward;
      }

      int startIndex = currentIndex;
      int endIndex = currentIndex;
      containersHeight = 0d;
      GeneratorPosition position;

      position = generator.GeneratorPositionFromIndex( currentIndex );
      int itemCount = generator.ItemCount;

      using( generator.StartAt( position, direction, true ) )
      {
        while( ( ( direction == GeneratorDirection.Forward )
          ? ( currentIndex < itemCount ) : ( currentIndex >= 0 ) ) && ( pageHeight > 0 ) )
        {
          UIElement container = this.GenerateContainer( generator, currentIndex, measureInvalidated );

          if( container == null )
            break;

          double containerHeight = container.DesiredSize.Height;

          m_layoutedContainers.Add( new LayoutedContainerInfo( currentIndex, container ) );
          layoutedContainersToRecycle.Remove( container );
          m_layoutedContainersToRecycle.Remove( container );

          if( ( direction == GeneratorDirection.Backward ) && ( ( pageHeight - containerHeight ) < 0 ) )
          {
            // We do not want to recycle the container since it will cause a re-invalidation of the measure and 
            // may cause an infinit loop.  This case has been observed with a MaxHeight set on the DataGridControl.
            break;
          }

          pageHeight -= containerHeight;
          containersHeight += containerHeight;
          endIndex = currentIndex;
          currentIndex += ( direction == GeneratorDirection.Forward ) ? 1 : -1;
        }
      }

      if( pageHeight > 0 )
      {
        if( direction == GeneratorDirection.Forward )
        {
          direction = GeneratorDirection.Backward;
        }
        else
        {
          direction = GeneratorDirection.Forward;
        }

        DataGridContext dataGridContext = DataGridControl.GetDataGridContext( this );

        if( ( direction == GeneratorDirection.Forward ) || ( ( dataGridContext == null ) || ( TableView.GetAutoFillLastPage( dataGridContext ) ) ) )
        {
          currentIndex = ( direction == GeneratorDirection.Forward ) ? startIndex + 1 : startIndex - 1;

          if( ( direction == GeneratorDirection.Forward ) ? ( currentIndex < itemCount ) : ( currentIndex >= 0 ) )
          {
            position = generator.GeneratorPositionFromIndex( currentIndex );

            using( generator.StartAt( position, direction, true ) )
            {
              // If we still have more space, try to get more container to fill up the page.
              while( ( ( direction == GeneratorDirection.Forward ) ?
                ( currentIndex < itemCount ) : ( currentIndex >= 0 ) ) && ( pageHeight > 0 ) )
              {
                UIElement container = this.GenerateContainer( generator, currentIndex, measureInvalidated );

                if( container == null )
                  break;

                double containerHeight = container.DesiredSize.Height;
                pageHeight -= containerHeight;

                m_layoutedContainers.Add( new LayoutedContainerInfo( currentIndex, container ) );
                layoutedContainersToRecycle.Remove( container );
                m_layoutedContainersToRecycle.Remove( container );

                if( ( direction == GeneratorDirection.Backward ) && ( pageHeight < 0 ) )
                {
                  // We do not want to recycle the container since it will cause a re-invalidation of the measure and 
                  // may cause an infinit loop.  This case has been observed with a MaxHeight set on the DataGridControl.
                  break;
                }

                containersHeight += containerHeight;
                startIndex = currentIndex;
                currentIndex += ( direction == GeneratorDirection.Forward ) ? 1 : -1;
              }
            }
          }
        }
      }

      m_layoutedContainers.Sort();

      if( startIndex > endIndex )
      {
        pageIndexes = new PageIndexes( endIndex, startIndex );
      }
      else
      {
        pageIndexes = new PageIndexes( startIndex, endIndex );
      }
    }
    private void RecycleContainer( ICustomItemContainerGenerator generator, LayoutedContainerInfo containerInfo )
    {
      Debug.Assert( containerInfo != null );

      var index = containerInfo.RealizedIndex;
      if( ( generator != null ) && ( index >= 0 ) )
      {
        try
        {
          var position = generator.GeneratorPositionFromIndex( index );
          generator.Remove( position, 1 );
        }
        catch
        {
          Debug.Fail( "Unable to remove container for containerIndex " + index );
        }
      }

      this.ClearContainer( containerInfo.Container );
    }
Exemplo n.º 12
0
    private void TrySafeRecycleContainer( ICustomItemContainerGenerator generator, int containerIndex, UIElement container )
    {
      int newIndex = -1;

      if( ( generator != null ) && ( containerIndex != -1 ) )
      {
        GeneratorPosition position = generator.GeneratorPositionFromIndex( containerIndex );
        if( ( position.Index != -1 ) && ( position.Offset == 0 ) )
        {
          newIndex = containerIndex;
        }
      }

      this.RecycleContainer( generator, newIndex, container );
    }
Exemplo n.º 13
0
    private void RecycleContainer( ICustomItemContainerGenerator generator, int containerIndex, UIElement container )
    {
      if( ( generator != null ) && ( containerIndex != -1 ) )
      {
        try
        {
          GeneratorPosition position = generator.GeneratorPositionFromIndex( containerIndex );
          generator.Remove( position, 1 );
        }
        catch
        {
          Debug.Fail( "Unable to remove container for containerIndex " + containerIndex );
        }
      }

      this.DisableElementNavigation( container );
      this.FreeRowSelector( container );
    }
Exemplo n.º 14
0
 private void RecycleContainers(
   HashSet<UIElement> layoutedContainersToRecycle,
   ICustomItemContainerGenerator generator )
 {
   foreach( UIElement containerToRecycle in layoutedContainersToRecycle )
   {
     this.RecycleContainer( generator, generator.GetRealizedIndexForContainer( containerToRecycle ), containerToRecycle );
   }
 }
    private void GenerateStickyFooters( ICustomItemContainerGenerator generator, bool measureInvalidated, ref UIElement focusedElement )
    {
      if( !this.AreFootersStickyCache && !this.AreGroupFootersStickyCache )
      {
        this.RecycleUnusedStickyContainers( generator, m_stickyFooters, null, ref focusedElement );
        m_stickyFooters.Clear();
        return;
      }

      CustomItemContainerGenerator customGenerator = ( CustomItemContainerGenerator )generator;

      int numberOfContainerChecked = 0;

      StickyContainerInfoList newStickyFooters = new StickyContainerInfoList();

      int layoutedContainerCount = m_layoutedContainers.Count;
      if( layoutedContainerCount > 0 )
      {
        // We must not generate sticky footers if the last container is not even at the bottom of the view!
        LayoutedContainerInfo bottomMostContainerInfo = m_layoutedContainers[ layoutedContainerCount - 1 ];
        double bottomMostContainerOffset = this.GetContainerOffsetFromIndex( bottomMostContainerInfo.RealizedIndex );

        if( ( bottomMostContainerOffset + m_containerHeight ) >= m_viewportHeight )
        {
          for( int i = layoutedContainerCount - 1; i >= 0; i-- )
          {
            LayoutedContainerInfo layoutedContainerInfo = m_layoutedContainers[ i ];
            UIElement layoutedContainer = layoutedContainerInfo.Container;

            // For each visible container, we must find what footers should be sticky for it.
            List<StickyContainerGenerated> stickyFooters =
              customGenerator.GenerateStickyFooters( layoutedContainer, this.AreFootersStickyCache, this.AreGroupFootersStickyCache );

            stickyFooters.Sort( StickyContainerGeneratedReverseComparer.Singleton );

            // For each sticky headers returned, we must get the index of the last container
            // that could need that container to be sticky. 
            foreach( StickyContainerGenerated stickyFooterInfo in stickyFooters )
            {
              UIElement stickyContainer = ( UIElement )stickyFooterInfo.StickyContainer;

              if( newStickyFooters.ContainsContainer( stickyContainer ) )
                continue;

              int firstContainerIndex = customGenerator.GetFirstHoldingContainerIndexForStickyFooter( stickyContainer );

              StickyContainerInfo stickyContainerInfo = new StickyContainerInfo( stickyContainer, stickyFooterInfo.Index, firstContainerIndex );
              newStickyFooters.Add( stickyContainerInfo );

              if( focusedElement == stickyContainer )
              {
                focusedElement = null;
              }

              this.HandleGeneratedStickyContainerPreparation( stickyFooterInfo, measureInvalidated );
            }

            // We only need to find the sticky footers for one 
            // more element than what is already sticky.
            int visibleStickyFootersCount = ( int )Math.Ceiling( ( this.AnimatedScrollInfo.ViewportHeight - this.GetStickyFootersRegionHeight( newStickyFooters ) ) / m_containerHeight );

            if( ( ++numberOfContainerChecked - visibleStickyFootersCount ) >= 1 )
              break;
          }
        }
      }

      foreach( StickyContainerInfo stickyFooterInfo in newStickyFooters )
      {
        int indexOf = m_layoutedContainers.IndexOfContainer( stickyFooterInfo.Container );

        if( indexOf > -1 )
        {
          m_layoutedContainers.RemoveAt( indexOf );
        }
      }

      this.RecycleUnusedStickyContainers( generator, m_stickyFooters, newStickyFooters, ref focusedElement );

      m_stickyFooters.Clear();
      m_stickyFooters.AddRange( newStickyFooters );
      m_stickyFooters.Sort( StickyContainerInfoReverseComparer.Singleton );
    }
 private UIElement RecycleAllContainers( ICustomItemContainerGenerator generator )
 {
   return this.RecycleContainers( generator, -1, -1 );
 }
    private UIElement GenerateContainer(
      ICustomItemContainerGenerator generator,
      int index,
      bool measureInvalidated,
      bool delayDataContext )
    {
      bool isNewlyRealized;
      UIElement container = ( UIElement )generator.GenerateNext( out isNewlyRealized );

      if( container != null )
      {
        if( isNewlyRealized )
        {
          if( !this.Children.Contains( container ) )
          {
            this.Children.Add( container );
          }

          this.EnableElementNavigation( container );
          KeyboardNavigation.SetTabIndex( container, index );
        }

        this.HandleGeneratedContainerPreparation( container, index, isNewlyRealized, delayDataContext );

        if( ( isNewlyRealized ) || ( measureInvalidated ) )
        {
          this.MeasureContainer( container );
        }
      }

      return container;
    }
Exemplo n.º 18
0
    private UIElement RecycleContainers(
      ICustomItemContainerGenerator generator,
      int pageStartIndex,
      int pageEndIndex )
    {
      UIElement focusedElement = null;

      for( int i = 0; i < m_layoutedContainers.Count; i++ )
      {
        LayoutedContainerInfo layoutedContainerInfo = m_layoutedContainers[ i ];
        UIElement container = layoutedContainerInfo.Container;

        // We do not recycle the focused element!
        if( container.IsKeyboardFocusWithin )
        {
          focusedElement = container;
          continue;
        }

        int index = generator.GetRealizedIndexForContainer( container );

        // If the container's index is now out of view, recycle that container.
        if( ( index < pageStartIndex ) || ( index > pageEndIndex ) )
        {
          this.RecycleContainer( generator, index, container );
          m_layoutedContainersToRecycle.Add( container );
        }
      }

      m_layoutedContainers.Clear();
      return focusedElement;
    }