示例#1
0
        private void RefreshScrollTipContent(ScrollBar scrollBar)
        {
            const int MaxItemToVisit = 100;

            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

            if (dataGridContext == null)
            {
                return;
            }

            DataGridControl parentGridControl = dataGridContext.DataGridControl;

            if (parentGridControl == null)
            {
                return;
            }

            if (scrollBar.Orientation != m_itemsScrollingOrientation)
            {
                return;
            }

            double maxOffset = 0;

            if (scrollBar.Orientation == Orientation.Vertical)
            {
                maxOffset = parentGridControl.ScrollViewer.ExtentHeight;
            }
            else
            {
                maxOffset = parentGridControl.ScrollViewer.ExtentWidth;
            }

            double offset = scrollBar.Track.Value;

            int itemMaxOffset = 0;
            int itemOffset    = 0;

            if (this.IsPixelScrolling)
            {
                // Calculate the offset ratio to get the item from the Generator
                int itemsCount = parentGridControl.CustomItemContainerGenerator.ItemCount;
                itemMaxOffset = itemsCount;

                if ((maxOffset > 0) && (itemsCount > 0))
                {
                    itemOffset = ( int )(offset / (maxOffset / itemsCount));
                }
                else
                {
                    itemOffset = 0;
                }
            }
            else
            {
                itemMaxOffset = ( int )maxOffset;
                itemOffset    = ( int )offset;
            }

            object          newValue    = null;
            DataGridContext itemContext = null;

            // If data is grouped, we do not want to keep the next data item if a HeaderFooterItem
            // is the current item returned. So we increment the scroll up to the next item in order
            // to get the real item that will be visible when the user will release the mouse
            ItemContextVisitor visitor = new ItemContextVisitor(parentGridControl.ItemsHost is TableflowViewItemsHost);
            int  endOffset             = Math.Min(itemOffset + MaxItemToVisit, itemMaxOffset);
            bool visitWasStopped;

            (( IDataGridContextVisitable )parentGridControl.DataGridContext).AcceptVisitor(itemOffset, endOffset, visitor, DataGridContextVisitorType.Items, out visitWasStopped);

            object tempValue = visitor.Item;

            if (visitor.VisitSuccessful)
            {
                newValue    = tempValue;
                itemContext = visitor.ParentDataGridContext;
            }
            else
            {
                //Set the ItemContext as the ScrollTip's DataGridContext, this is to ensure the
                //ScrollTip will not change the ScrollContentTemplate ( by invalidation of the binding).
                itemContext = DataGridControl.GetDataGridContext(this);
                newValue    = null; //show nothing in the ScrollTip.
            }

            // The TippedItemDataGridContext PropertChanged callback will take care of refreshing the ScrollTip CellContentTemplate.
            if (itemContext != DataGridControl.GetDataGridContext(this))
            {
                DataGridControl.SetDataGridContext(this, itemContext);
            }

            if (this.Content != newValue)
            {
                this.Content = newValue;
            }
        }
示例#2
0
    private void RefreshScrollTipContent( ScrollBar scrollBar )
    {
      const int MaxItemToVisit = 100;

      DataGridContext dataGridContext = DataGridControl.GetDataGridContext( this );

      if( dataGridContext == null )
        return;

      DataGridControl parentGridControl = dataGridContext.DataGridControl;

      if( parentGridControl == null )
        return;

      if( scrollBar.Orientation != m_itemsScrollingOrientation )
        return;

      double maxOffset = 0;

      if( scrollBar.Orientation == Orientation.Vertical )
      {
        maxOffset = parentGridControl.ScrollViewer.ExtentHeight;
      }
      else
      {
        maxOffset = parentGridControl.ScrollViewer.ExtentWidth;
      }

      double offset = scrollBar.Track.Value;

      int itemMaxOffset = 0;
      int itemOffset = 0;

      if( this.IsPixelScrolling )
      {
        // Calculate the offset ratio to get the item from the Generator
        int itemsCount = parentGridControl.CustomItemContainerGenerator.ItemCount;
        itemMaxOffset = itemsCount;

        if( ( maxOffset > 0 ) && ( itemsCount > 0 ) )
        {
          itemOffset = ( int )( offset / ( maxOffset / itemsCount ) );
        }
        else
        {
          itemOffset = 0;
        }
      }
      else
      {
        itemMaxOffset = ( int )maxOffset;
        itemOffset = ( int )offset;
      }

      object newValue = null;
      DataGridContext itemContext = null;

      // If data is grouped, we do not want to keep the next data item if a HeaderFooterItem
      // is the current item returned. So we increment the scroll up to the next item in order
      // to get the real item that will be visible when the user will release the mouse
      ItemContextVisitor visitor = new ItemContextVisitor( parentGridControl.ItemsHost is TableflowViewItemsHost );
      int endOffset = Math.Min( itemOffset + MaxItemToVisit, itemMaxOffset );
      bool visitWasStopped;
      ( ( IDataGridContextVisitable )parentGridControl.DataGridContext ).AcceptVisitor( itemOffset, endOffset, visitor, DataGridContextVisitorType.Items, out visitWasStopped );

      object tempValue = visitor.Item;

      if( visitor.VisitSuccessful )
      {
        newValue = tempValue;
        itemContext = visitor.ParentDataGridContext;
      }
      else
      {
        //Set the ItemContext as the ScrollTip's DataGridContext, this is to ensure the
        //ScrollTip will not change the ScrollContentTemplate ( by invalidation of the binding).
        itemContext = DataGridControl.GetDataGridContext( this );
        newValue = null; //show nothing in the ScrollTip.
      }

      // The TippedItemDataGridContext PropertChanged callback will take care of refreshing the ScrollTip CellContentTemplate.
      if( itemContext != DataGridControl.GetDataGridContext( this ) )
        DataGridControl.SetDataGridContext( this, itemContext );

      if( this.Content != newValue )
        this.Content = newValue;
    }