本文整理汇总了C#中System.Windows.FrameworkElement.BringIntoView方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElement.BringIntoView方法的具体用法?C# FrameworkElement.BringIntoView怎么用?C# FrameworkElement.BringIntoView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.FrameworkElement
的用法示例。
在下文中一共展示了FrameworkElement.BringIntoView方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BringIntoViewScrollingCell
private bool BringIntoViewScrollingCell( Cell cell, FrameworkElement container, RequestBringIntoViewEventArgs e )
{
Debug.Assert( cell != null );
Debug.Assert( container != null );
// The cell must be measured/arranged for the BringIntoView to correctly reacts
if( this.ForceScrollingCellToLayout( cell ) )
{
container.UpdateLayout();
}
var fixedWidth = this.GetFixedWidth();
var scrollingPanel = this.ScrollingCellsDecorator;
var scrollingArea = new Rect( scrollingPanel.TranslatePoint( FixedCellPanel.EmptyPoint, this ),
new Size( this.ParentScrollViewer.ViewportWidth - fixedWidth, scrollingPanel.ActualHeight ) );
var cellArea = new Rect( cell.TranslatePoint( FixedCellPanel.EmptyPoint, this ),
new Size( cell.ParentColumn.ActualWidth, cell.ActualHeight ) );
// The cell is larger than the scrolling area.
if( cellArea.Width > scrollingArea.Width )
{
var targetObject = e.TargetObject as UIElement;
var targetRect = e.TargetRect;
// Try to narrow the area within the cell that we clearly want to bring into view.
if( ( targetObject != null ) && ( targetObject != cell || !targetRect.IsEmpty ) )
{
Debug.Assert( targetObject.IsDescendantOf( cell ) );
if( targetRect.IsEmpty )
{
targetRect = new Rect( new Point( 0d, 0d ), targetObject.RenderSize );
}
if( targetRect.Width <= scrollingArea.Width )
{
var offset = targetObject.TranslatePoint( FixedCellPanel.EmptyPoint, cell );
var location = cellArea.Location;
location.Offset( offset.X, offset.Y );
cellArea.Location = location;
cellArea.Size = targetRect.Size;
}
}
}
if( ( cellArea.Left <= scrollingArea.Left ) && ( cellArea.Right >= scrollingArea.Right ) )
{
// Ensure to bring the container into view vertically.
container.BringIntoView();
}
else if( cellArea.Left < scrollingArea.Left )
{
// The ScrollViewer's extent width includes the fixed section. We must offset the target area or the cell
// will come into view under the fixed panel.
cellArea.X -= fixedWidth;
this.BringIntoView( cellArea );
}
else if( cellArea.Right > scrollingArea.Right )
{
this.BringIntoView( cellArea );
}
// The cell is fully visible.
else
{
// Ensure to bring the container into view vertically.
container.BringIntoView();
}
return true;
}
示例2: MakeVisible
//
// Shifts the viewport to make the given index visible.
//
internal void MakeVisible(FrameworkElement container, FocusNavigationDirection direction, bool alwaysAtTopOfViewport)
{
if (ScrollHost != null && ItemsHost != null)
{
double oldHorizontalOffset;
double oldVerticalOffset;
FrameworkElement viewportElement = GetViewportElement();
while (container != null && !IsOnCurrentPage(viewportElement, container, direction, false /*fullyVisible*/))
{
oldHorizontalOffset = ScrollHost.HorizontalOffset;
oldVerticalOffset = ScrollHost.VerticalOffset;
container.BringIntoView();
// Wait for layout
ItemsHost.UpdateLayout();
// If offset does not change - exit the loop
if (DoubleUtil.AreClose(oldHorizontalOffset, ScrollHost.HorizontalOffset) &&
DoubleUtil.AreClose(oldVerticalOffset, ScrollHost.VerticalOffset))
break;
}
if (container != null && alwaysAtTopOfViewport)
{
bool isHorizontal = (ItemsHost.HasLogicalOrientation && ItemsHost.LogicalOrientation == Orientation.Horizontal);
FrameworkElement firstElement;
GetFirstItemOnCurrentPage(container, FocusNavigationDirection.Up, out firstElement);
while (firstElement != container)
{
oldHorizontalOffset = ScrollHost.HorizontalOffset;
oldVerticalOffset = ScrollHost.VerticalOffset;
if (isHorizontal)
{
ScrollHost.LineRight();
}
else
{
ScrollHost.LineDown();
}
ScrollHost.UpdateLayout();
// If offset does not change - exit the loop
if (DoubleUtil.AreClose(oldHorizontalOffset, ScrollHost.HorizontalOffset) &&
DoubleUtil.AreClose(oldVerticalOffset, ScrollHost.VerticalOffset))
break;
GetFirstItemOnCurrentPage(container, FocusNavigationDirection.Up, out firstElement);
}
}
}
}
示例3: BringIntoViewFixedCell
private bool BringIntoViewFixedCell( FrameworkElement container )
{
Debug.Assert( container != null );
// We always want the horizontal offset to change if Tab, Home, Left or Right is pressed.
if( Keyboard.IsKeyDown( Key.Tab ) || Keyboard.IsKeyDown( Key.Home ) || Keyboard.IsKeyDown( Key.Left ) || Keyboard.IsKeyDown( Key.Right ) )
{
container.BringIntoView( new Rect( 0d, 0d, 0d, 0d ) );
}
else
{
// Ensure to bring the container into view vertically.
container.BringIntoView();
}
return true;
}