本文整理汇总了C#中System.Windows.Controls.ScrollViewer.ScrollToHorizontalOffset方法的典型用法代码示例。如果您正苦于以下问题:C# ScrollViewer.ScrollToHorizontalOffset方法的具体用法?C# ScrollViewer.ScrollToHorizontalOffset怎么用?C# ScrollViewer.ScrollToHorizontalOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.ScrollViewer
的用法示例。
在下文中一共展示了ScrollViewer.ScrollToHorizontalOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ScrollByHorizontalOffset
/// <summary>
/// Scroll a ScrollViewer horizontally by a given offset.
/// </summary>
/// <param name="viewer">The ScrollViewer.</param>
/// <param name="offset">The horizontal offset to scroll.</param>
private static void ScrollByHorizontalOffset(ScrollViewer viewer, double offset)
{
Debug.Assert(viewer != null, "viewer should not be null!");
offset += viewer.HorizontalOffset;
offset = Math.Max(Math.Min(offset, viewer.ExtentWidth), 0);
viewer.ScrollToHorizontalOffset(offset);
}
示例2: scrollViewer_Loaded
private void scrollViewer_Loaded(object sender, EventArgs e)
{
scrollViewer = (ScrollViewer)sender;
if (scrollToIndex != -1)
{
scrollViewer.ScrollToHorizontalOffset(scrollToIndex);
}
}
示例3: ScrollToCurrentSlide
//Todo: This was done by experimentation and is by all accounts an ugly hack! Research into a better solution should be undertaken!
private void ScrollToCurrentSlide(ScrollViewer scrollviewer)
{
var slideshowDialog = this.DataContext as EditSlideshowDialog;
if(slideshowDialog != null && slideshowDialog.Slideshow != null)
{
var slideShow = slideshowDialog.Slideshow;
var currentSlide = slideShow.CurrentSlide;
var index = slideShow.Slides.IndexOf(currentSlide);
if (index <= 1)
{
scrollviewer.ScrollToHorizontalOffset(1);
}
else
{
scrollviewer.ScrollToHorizontalOffset( 138 * (index-1));
}
}
}
示例4: AutoScroll
static void AutoScroll(Point positionInScrollViewer, ScrollViewer scrollViewer, Point? positionInLogicalView, FrameworkElement logicalView, double scrollOnDragThresholdX, double scrollOnDragThresholdY, int scrollOnDragOffset)
{
double scrollViewerWidth = scrollViewer.ActualWidth;
double scrollViewerHeight = scrollViewer.ActualHeight;
double logicalViewWidth = 0;
double logicalViewHeight = 0;
if (logicalView != null)
{
logicalViewWidth = logicalView.ActualWidth;
logicalViewHeight = logicalView.ActualHeight;
}
int heightToScroll = 0;
int widthToScroll = 0;
if (positionInScrollViewer.X > (scrollViewerWidth - scrollOnDragThresholdX)
&& (positionInLogicalView == null
|| positionInLogicalView.Value.X < (logicalViewWidth - scrollBuffer)))
{
widthToScroll = scrollOnDragOffset;
}
else if (positionInScrollViewer.X < scrollOnDragThresholdX
&& (positionInLogicalView == null
|| positionInLogicalView.Value.X > scrollBuffer))
{
widthToScroll = -scrollOnDragOffset;
}
if (positionInScrollViewer.Y > (scrollViewerHeight - scrollOnDragThresholdY)
&& (positionInLogicalView == null
|| positionInLogicalView.Value.Y < logicalViewHeight - scrollBuffer))
{
heightToScroll = scrollOnDragOffset;
}
else if (positionInScrollViewer.Y < scrollOnDragThresholdY
&& (positionInLogicalView == null
|| positionInLogicalView.Value.Y > scrollBuffer))
{
heightToScroll = -scrollOnDragOffset;
}
if (widthToScroll != 0 || heightToScroll != 0)
{
scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + heightToScroll);
scrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset + widthToScroll);
}
}
示例5: BranchHidden
public void BranchHidden(int position, bool isFunctionHidden, ref ScrollViewer scrollviewer)
{
if (isFunctionHidden)
{
setBranchHidden(pieces[position].functionName);
}
else
{
setBranchHidden(position);
}
visualDict.Clear();
drawingCanvas.clear();
double preX = pieces[position].topLeftCorner.X;
calculate();
double nowX = pieces[position].topLeftCorner.X;
if (scrollviewer.HorizontalOffset - preX + nowX >= 0)
scrollviewer.ScrollToHorizontalOffset(scrollviewer.HorizontalOffset - preX + nowX);
else
shiftChildTree(-1, pieces.Count, preX - nowX);
drawTreeGraph();
double maxMostRight = 0;
for (int i = 0; i < mostRight.Count; i++)
{
if (maxMostRight < mostRight[i])
maxMostRight = mostRight[i];
}
if (drawingCanvas.Width < maxMostRight + Constant.hDelta)
drawingCanvas.Width = maxMostRight + Constant.hDelta;
if (drawingCanvas.Height < (maxDepth) * Constant.vDelta)
drawingCanvas.Height = (maxDepth) * Constant.vDelta;
}
示例6: setChildHidden
public void setChildHidden(Point point, ref ScrollViewer scrollviewer)
{
DrawingVisual visual = drawingCanvas.GetVisual(point);
if (visual != null && visualDict.ContainsKey(visual))
{
if ( !(pieces[visualDict[visual]].isChildTreeHidden==false&& pieces[visualDict[visual]].sonNum == 0) )
{
pieces[visualDict[visual]].isChildTreeHidden = !pieces[visualDict[visual]].isChildTreeHidden;
int it = visualDict[visual];
visualDict.Clear();
drawingCanvas.clear();
double preX = pieces[it].topLeftCorner.X;
calculate();
double nowX = pieces[it].topLeftCorner.X;
if (scrollviewer.HorizontalOffset - preX + nowX >= 0)
scrollviewer.ScrollToHorizontalOffset(scrollviewer.HorizontalOffset - preX + nowX);
else
shiftChildTree(-1, pieces.Count, preX - nowX);
drawTreeGraph();
double maxMostRight = 0;
for (int i = 0; i < mostRight.Count; i++)
{
if (maxMostRight < mostRight[i])
maxMostRight = mostRight[i];
}
if (drawingCanvas.Width < maxMostRight + Constant.hDelta)
drawingCanvas.Width = maxMostRight + Constant.hDelta;
if (drawingCanvas.Height < (maxDepth) * Constant.vDelta)
drawingCanvas.Height = (maxDepth) * Constant.vDelta;
}
}
}
示例7: set
private void set(ScrollChangedEventArgs e, ScrollViewer sv, Canvas canvas)
{
if (e.ExtentHeightChange != 0 || e.ExtentWidthChange != 0)
{
Point? targetBefore = null;
Point? targetNow = null;
if (!lastMousePositionOnTarget.HasValue)
{
if (lastCenterPositionOnTarget.HasValue)
{
var centerOfViewport = new Point(sv.ViewportWidth / 2, sv.ViewportHeight / 2);
Point centerOfTargetNow = sv.TranslatePoint(centerOfViewport, canvas);
targetBefore = lastCenterPositionOnTarget;
targetNow = centerOfTargetNow;
}
}
else
{
targetBefore = lastMousePositionOnTarget;
targetNow = Mouse.GetPosition(canvas);
lastMousePositionOnTarget = null;
}
if (targetBefore.HasValue)
{
double dXInTargetPixels = targetNow.Value.X - targetBefore.Value.X;
double dYInTargetPixels = targetNow.Value.Y - targetBefore.Value.Y;
double multiplicatorX = e.ExtentWidth / canvas.Width;
double multiplicatorY = e.ExtentHeight / canvas.Height;
double newOffsetX = sv.HorizontalOffset - dXInTargetPixels * multiplicatorX;
double newOffsetY = sv.VerticalOffset - dYInTargetPixels * multiplicatorY;
if (double.IsNaN(newOffsetX) || double.IsNaN(newOffsetY))
{
return;
}
sv.ScrollToHorizontalOffset(newOffsetX);
sv.ScrollToVerticalOffset(newOffsetY);
}
}
}
示例8: AddScrollViewerMouseWheelSupport
static ScrollViewer AddScrollViewerMouseWheelSupport(ScrollViewer scrollViewer, double scrollAmount)
{
if(mouseWheelHelper != null)
{
mouseWheelHelper.MouseWheelMoved += (source, eventArgs) =>
{
var delta = eventArgs.WheelDelta;
delta *= scrollAmount;
if (eventArgs.IsHorizontal)
{
var newOffset = scrollViewer.HorizontalOffset - delta;
if (newOffset > scrollViewer.ScrollableWidth)
newOffset = scrollViewer.ScrollableWidth;
else if (newOffset < 0)
newOffset = 0;
scrollViewer.ScrollToHorizontalOffset(newOffset);
}
else
{
var newOffset = scrollViewer.VerticalOffset - delta;
if (newOffset > scrollViewer.ScrollableHeight)
newOffset = scrollViewer.ScrollableHeight;
else if (newOffset < 0)
newOffset = 0;
scrollViewer.ScrollToVerticalOffset(newOffset);
}
eventArgs.BrowserEventHandled = true;
};
}
return scrollViewer;
}
开发者ID:SmallMobile,项目名称:ranet-uilibrary-olap.latest-unstabilized,代码行数:37,代码来源:ScrollViewerMouseWheelSupport.cs
示例9: AdjustScrollPosition
/// <summary>
/// This is the command scroll adjustment code which synchronizes two ScrollViewer instances.
/// </summary>
/// <param name="sv">ScrollViewer to adjust</param>
/// <param name="e">Change in the source</param>
/// <param name="hadjust">Horizontal adjustment</param>
/// <param name="vadjust">Vertical adjustment</param>
private static void AdjustScrollPosition(ScrollViewer sv, ScrollChangedEventArgs e, double hadjust, double vadjust)
{
if (e.HorizontalChange != 0 || e.ExtentWidthChange != 0)
{
if (e.HorizontalOffset == 0)
sv.ScrollToLeftEnd();
else if (e.HorizontalOffset >= e.ExtentWidth-5)
sv.ScrollToRightEnd();
else if (e.ExtentWidth + hadjust == sv.ExtentWidth)
sv.ScrollToHorizontalOffset(e.HorizontalOffset + hadjust);
else
sv.ScrollToHorizontalOffset((sv.ExtentWidth * (e.HorizontalOffset / e.ExtentWidth)) + hadjust);
}
if (e.VerticalChange != 0 || e.ExtentHeightChange != 0)
{
if (e.VerticalOffset == 0)
sv.ScrollToTop();
else if (e.VerticalOffset >= e.ExtentHeight-5)
sv.ScrollToBottom();
else if (e.ExtentHeight + vadjust == sv.ExtentHeight)
sv.ScrollToVerticalOffset(e.VerticalOffset + vadjust);
else
sv.ScrollToVerticalOffset((sv.ExtentHeight * (e.VerticalOffset / e.ExtentHeight)) + vadjust);
}
}
示例10: ScrollByHorizontalOffset
/// <summary>
/// Scroll a ScrollViewer horizontally by a given offset.
/// </summary>
/// <param name="viewer">The ScrollViewer.</param>
/// <param name="offset">The horizontal offset to scroll.</param>
private static void ScrollByHorizontalOffset(ScrollViewer viewer, double offset)
{
Debug.Assert(viewer != null, "viewer should not be null!");
offset += viewer.HorizontalOffset;
offset = CoerceHorizontalOffset(viewer, offset);
viewer.ScrollToHorizontalOffset(offset);
}
示例11: GetScrollBarsForScrollViewer
/// <summary>
/// Attempts to extract the scrollbars that are within the scrollviewers
/// visual tree. When extracted, event handlers are added to their ValueChanged events.
/// </summary>
private static void GetScrollBarsForScrollViewer(ScrollViewer scrollViewer)
{
ScrollBar scroll = GetScrollBar(scrollViewer, Orientation.Vertical);
if (scroll != null)
{
// save a reference to this scrollbar on the attached property
scrollViewer.SetValue(VerticalScrollBarProperty, scroll);
// scroll the scrollviewer
scrollViewer.ScrollToVerticalOffset(GetVerticalOffset(scrollViewer));
// handle the changed event to update the exposed VerticalOffset
scroll.ValueChanged += (s, e) => SetVerticalOffset(scrollViewer, e.NewValue);
}
scroll = GetScrollBar(scrollViewer, Orientation.Horizontal);
if (scroll != null)
{
// save a reference to this scrollbar on the attached property
scrollViewer.SetValue(HorizontalScrollBarProperty, scroll);
// scroll the scrollviewer
scrollViewer.ScrollToHorizontalOffset(GetHorizontalOffset(scrollViewer));
// handle the changed event to update the exposed HorizontalOffset
scroll.ValueChanged += (s, e) => scrollViewer.SetValue(HorizontalOffsetProperty, e.NewValue);
}
}
示例12: TranslationChanged
/// <summary>
/// 滑动改变
/// </summary>
/// <param name="isLeft">滑动方向 </param>
/// <param name="scrollViewer">自动调整的控件</param>
/// <param name="width">单个间隔的宽度</param>
public int TranslationChanged(bool isLeft,ScrollViewer scrollViewer,double width)
{
int newSelected;
if (!isLeft)
{
newSelected = _selecter + 1;
}
else
{
newSelected = _selecter - 1;
}
//循环切换
if (newSelected < 0) newSelected = _effects.Count - 1;
if (newSelected >= _effects.Count) newSelected = 0;
//自动调整位置
if (newSelected >= 3)
{
//判断方向
if (scrollViewer.HorizontalScrollBarVisibility != ScrollBarVisibility.Disabled)
{
scrollViewer.ScrollToHorizontalOffset(width * (newSelected - 2));
}
else
{
scrollViewer.ScrollToVerticalOffset(width * (newSelected - 2));
}
}
else
{
if (scrollViewer.HorizontalScrollBarVisibility != ScrollBarVisibility.Disabled)
{
scrollViewer.ScrollToHorizontalOffset(0);
}
else
{
scrollViewer.ScrollToVerticalOffset(0);
}
}
//变化效果
SelectedChanged(newSelected);
return newSelected;
}
示例13: ScrollByHorizontalOffset
private static void ScrollByHorizontalOffset(ScrollViewer viewer, double offset)
{
offset += viewer.HorizontalOffset;
offset = ScrollViewerExtensions.CoerceHorizontalOffset(viewer, offset);
viewer.ScrollToHorizontalOffset(offset);
}
示例14: ScrollToCenter
public static void ScrollToCenter(ScrollViewer scrollViewer)
{
scrollViewer.ScrollToHorizontalOffset(scrollViewer.ExtentWidth / 2 - scrollViewer.Width / 2);
scrollViewer.ScrollToVerticalOffset(scrollViewer.ExtentHeight / 2 - scrollViewer.Height / 2);
}
示例15: AddAndRemoveImage
/// <summary>
/// Добавляет изображение в StackPanel с одной стороны и удоляет изображение с другой
///</summary>
///<remarks>Следит что бы было только 3 изображения в StackPanel</remarks>
/// <param name="panel">ScrollViewer</param>
public void AddAndRemoveImage(ScrollViewer panel)
{
var someWidth = panel.HorizontalOffset; //текущее состояние прокрутки
Image img;
if (Math.Abs(someWidth - panel.ScrollableWidth) < 0.001) //ScrollableWidth - максимально возможная прокрутка
{
img = new Image
{
Width = _size.Width,
Height = _size.Height,
Source = NextImg(NextImage.Right)
};
StackPanel1.Children.Add(img);
if (StackPanel1.Children.Count > 3)
StackPanel1.Children.RemoveAt(0);
panel.ScrollToHorizontalOffset(panel.ScrollableWidth - img.Width);
}
if(StackPanel1.Children.Count > 1)
_indexCurr = ImageList.Children.IndexOf(StackPanel1.Children[1]);
if (Math.Abs(someWidth) > 0.001) return;
img = new Image
{
Width = _size.Width,
Height = _size.Height,
Source = NextImg(NextImage.Left)
};
StackPanel1.Children.Insert(0, img);
if (StackPanel1.Children.Count > 3)
StackPanel1.Children.RemoveAt(StackPanel1.Children.Count - 1);
panel.ScrollToHorizontalOffset(0 + img.Width);
if (StackPanel1.Children.Count > 1)
_indexCurr = ImageList.Children.IndexOf(StackPanel1.Children[1]);
}