本文整理汇总了C#中System.Windows.FrameworkElement.TranslatePoint方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElement.TranslatePoint方法的具体用法?C# FrameworkElement.TranslatePoint怎么用?C# FrameworkElement.TranslatePoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.FrameworkElement
的用法示例。
在下文中一共展示了FrameworkElement.TranslatePoint方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartDragDrop
public void StartDragDrop(ItemsControl source, FrameworkElement sourceItemContainer, object draggedData, Point initialMousePosition)
{
_topWindow = Window.GetWindow(source);
Debug.Assert(_topWindow != null);
_source = source;
_sourceItemContainer = sourceItemContainer;
_initialMousePosition = initialMousePosition;
_initialMouseOffset = _initialMousePosition - _sourceItemContainer.TranslatePoint(new Point(0, 0), _topWindow);
var data = new DataObject(Format.Name, draggedData);
// Adding events to the window to make sure dragged adorner comes up when mouse is not over a drop target.
bool previousAllowDrop = _topWindow.AllowDrop;
_topWindow.AllowDrop = true;
_topWindow.DragEnter += TopWindow_DragEnter;
_topWindow.DragOver += TopWindow_DragOver;
_topWindow.DragLeave += TopWindow_DragLeave;
DragDrop.DoDragDrop(_source, data, DragDropEffects.Move);
// Without this call, there would be a bug in the following scenario: Click on a data item, and drag
// the mouse very fast outside of the window. When doing this really fast, for some reason I don't get
// the Window leave event, and the dragged adorner is left behind.
// With this call, the dragged adorner will disappear when we release the mouse outside of the window,
// which is when the DoDragDrop synchronous method returns.
RemoveDraggedAdorner();
_topWindow.AllowDrop = previousAllowDrop;
_topWindow.DragEnter -= TopWindow_DragEnter;
_topWindow.DragOver -= TopWindow_DragOver;
_topWindow.DragLeave -= TopWindow_DragLeave;
}
示例2: RotateThumb_DragStarted
private void RotateThumb_DragStarted(object sender, DragStartedEventArgs e)
{
adornedElement = this.AdornedElement as FrameworkElement;
Thumb hitThumb = sender as Thumb;
if (adornedElement == null || hitThumb == null) return;
parentElement = adornedElement.Parent as FrameworkElement;
if (parentElement != null)
{
this.centerPoint = adornedElement.TranslatePoint(
new Point(adornedElement.Width * 0.5,
adornedElement.Height * 0.5),
parentElement);
Point startPoint = Mouse.GetPosition(parentElement);
this.startVector = Point.Subtract(startPoint, this.centerPoint);
this.rotateTransform = adornedElement.RenderTransform as RotateTransform;
if (this.rotateTransform == null)
{
adornedElement.RenderTransform = new RotateTransform(
0, adornedElement.Width * 0.5, adornedElement.Height * 0.5);
this.initialAngle = 0;
}
else
{
this.initialAngle = this.rotateTransform.Angle;
}
}
}
示例3: QueryContinueDrag
/// <summary>
/// ドラッグ中処理
/// </summary>
/// <param name="owner"></param>
public void QueryContinueDrag(FrameworkElement owner)
{
if (Ghost != null) {
var p = CursorInfo.GetNowPosition(owner);
var loc = owner.PointFromScreen(owner.PointToScreen(new Point(0, 0)));
Point renderedLocation = owner.TranslatePoint(new Point(0, 0), Window.GetWindow(owner));
Ghost.LeftOffset = p.X - loc.X - renderedLocation.X;
Ghost.TopOffset = p.Y - loc.Y - renderedLocation.Y;
}
}
示例4: FixedPosition
/// <summary>
/// 定位
/// </summary>
/// <param name="control"></param>
/// <param name="orientation"></param>
private void FixedPosition(FrameworkElement control, TipOrientation orientation, ContentControl Commain)
{
//尖角的长度
int angleLength = 5;
double tipWidht = tipCallout.Width;
double tipHeight = tipCallout.Height;
//控件距离窗体边界的距离
Point screenPoint = control.TranslatePoint(new Point(0, 0), Commain);
switch (orientation)
{
case TipOrientation.up:
if (screenPoint.Y > tipHeight + angleLength &&
Commain.ActualWidth - screenPoint.X - tipWidht > 0)
{
this.tipCallout.AnchorPoint = tipPosition[TipOrientation.up];
this.Margin = new Thickness(screenPoint.X, screenPoint.Y - tipHeight - angleLength, 0, 0);
}
else
goto case TipOrientation.upRight;
break;
case TipOrientation.upRight:
if (Commain.ActualWidth - screenPoint.X - control.ActualWidth / 2 > tipWidht &&
screenPoint.Y > tipHeight + angleLength
)
{
this.tipCallout.AnchorPoint = tipPosition[TipOrientation.upRight];
this.Margin = new Thickness(screenPoint.X + control.ActualWidth / 2, screenPoint.Y - tipHeight - angleLength, 0, 0);
}
else
goto case TipOrientation.right;
break;
case TipOrientation.right:
if (Commain.ActualWidth - screenPoint.X - control.ActualWidth > tipWidht + angleLength &&
Commain.ActualHeight - screenPoint.Y - tipHeight > 0)
{
this.tipCallout.AnchorPoint = tipPosition[TipOrientation.right];
this.Margin = new Thickness(screenPoint.X + control.ActualWidth + angleLength, screenPoint.Y, 0, 0);
}
else
goto case TipOrientation.downRight;
break;
case TipOrientation.downRight:
if (Commain.ActualWidth - screenPoint.X - control.ActualWidth / 2 > tipWidht &&
Commain.ActualHeight - screenPoint.Y - control.ActualHeight > tipHeight + angleLength
)
{
this.tipCallout.AnchorPoint = tipPosition[TipOrientation.downRight];
this.Margin = new Thickness(screenPoint.X + control.ActualWidth / 2, screenPoint.Y + control.ActualHeight + angleLength, 0, 0);
}
else
goto case TipOrientation.down;
break;
case TipOrientation.down:
if (Commain.ActualHeight - screenPoint.Y - control.ActualHeight > tipHeight + angleLength &&
Commain.ActualWidth - screenPoint.X - tipWidht > 0
)
{
this.tipCallout.AnchorPoint = tipPosition[TipOrientation.down];
this.Margin = new Thickness(screenPoint.X, screenPoint.Y + control.ActualHeight + angleLength, 0, 0);
}
else
{
goto case TipOrientation.downLeft;
}
break;
case TipOrientation.downLeft:
if (screenPoint.X + control.ActualWidth / 2 > tipWidht &&
Commain.ActualHeight - screenPoint.Y - control.ActualHeight > tipHeight + angleLength
)
{
this.tipCallout.AnchorPoint = tipPosition[TipOrientation.downLeft];
this.Margin = new Thickness(screenPoint.X + control.ActualWidth / 2 - tipWidht, screenPoint.Y + control.ActualHeight + angleLength, 0, 0);
}
else
goto case TipOrientation.left;
break;
case TipOrientation.left:
if (screenPoint.X > tipWidht + angleLength &&
Commain.ActualHeight - screenPoint.Y - tipHeight > 0)
{
this.tipCallout.AnchorPoint = tipPosition[TipOrientation.left];
this.Margin = new Thickness(screenPoint.X - tipWidht - angleLength, screenPoint.Y, 0, 0);
}
else
goto case TipOrientation.upLeft;
break;
case TipOrientation.upLeft:
if (screenPoint.X + control.ActualWidth / 2 > tipWidht && screenPoint.Y > tipHeight + angleLength)
{
this.tipCallout.AnchorPoint = tipPosition[TipOrientation.upLeft];
this.Margin = new Thickness(screenPoint.X + control.ActualWidth / 2 - tipWidht, screenPoint.Y - tipHeight - angleLength, 0, 0);
}
else
//.........这里部分代码省略.........
示例5: OnDragStart
internal void OnDragStart(FrameworkElement child, Point origin, Point position)
{
if (child == null)
return;
Dispatcher.Invoke(() =>
{
child.Opacity = DragOpacity;
child.SetValue(ZIndexProperty, DragZ);
// Dragging point within the moving element
dragStart = new Point(origin.X * DragScale, origin.Y * DragScale);
// Apply transform without moving the element
Point translatePosition = child.TranslatePoint(new Point(-child.Margin.Left, -child.Margin.Top), this);
child.RenderTransform = CreateTransform(translatePosition.X, translatePosition.Y, DragScale, DragScale);
// Capture further mouse events
child.CaptureMouse();
// Record the initial position of the element
dragSourcePage = GetPageIndex(position);
dragSourceCell = GetCellIndex(position);
//
dragging = child;
});
}
示例6: ComputeCardCenterPos
/// <summary>
/// Compute card position on global canvas such that the card center is aligned to the center of <paramref name="element"/>.
/// </summary>
/// <param name="card">Card to be aligned.</param>
/// <param name="element">FrameworkElement to be aligned to.</param>
/// <returns>Position of card relative to global canvas.</returns>
protected Point ComputeCardCenterPos(CardView card, FrameworkElement element)
{
double width = element.ActualWidth;
double height = element.ActualHeight;
if (width == 0) width = element.Width;
if (height == 0) height = element.Height;
Point dest = element.TranslatePoint(new Point(element.Width / 2, element.Height / 2),
ParentGameView.GlobalCanvas);
dest.Offset(-card.Width / 2, -card.Height / 2);
return dest;
}
示例7: ToTouchEventArgs
/// <summary>
/// Converts <see cref="ManipulationCompletedEventArgs" /> to <see cref="OxyMouseEventArgs" /> for a touch completed event.
/// </summary>
/// <param name="e">The <see cref="ManipulationCompletedEventArgs" /> instance containing the event data.</param>
/// <param name="source">The <see cref="FrameworkElement"/> that is event source</param>
/// <param name="relativeTo">The <see cref="UIElement" /> that the event is relative to.</param>
/// <param name="offset">The <see cref="Vector" /> offset that event is relative to.</param>
/// <returns>A <see cref="OxyMouseEventArgs" /> containing the converted event arguments.</returns>
public static OxyTouchEventArgs ToTouchEventArgs(this ManipulationCompletedEventArgs e, FrameworkElement source, FrameworkElement relativeTo, Vector offset)
{
return new OxyTouchEventArgs
{
Position = (source.TranslatePoint(e.ManipulationOrigin, relativeTo) + offset).ToScreenPoint(),
};
}
示例8: GetTreeViewItemClicked
private TreeViewItem GetTreeViewItemClicked(FrameworkElement sender, TreeView treeView)
{
Point p = sender.TranslatePoint(new Point(1, 1), treeView);
DependencyObject obj = treeView.InputHitTest(p) as DependencyObject;
while (obj != null && !(obj is TreeViewItem)) {
obj = VisualTreeHelper.GetParent(obj);
}
return obj as TreeViewItem;
}
示例9: ElementIsInContainer
private bool ElementIsInContainer(FrameworkElement element, FrameworkElement container)
{
var relativePosition = element.TranslatePoint(new Point(), container);
return (relativePosition.X == 0) && (element.ActualWidth <= container.ActualWidth);
}
示例10: Center
private void Center(FrameworkElement hex)
{
if(hex == null)
return;
var centerPoint = center.TranslatePoint(new Point(0, 0), root);
var hexPoint = hex.TranslatePoint(new Point(hex.ActualWidth / 2.0, hex.ActualHeight / 2.0), root);
var transform = list.RenderTransform as TranslateTransform; // = new TranslateTransform(centerPoint.X - hexPoint.X, centerPoint.Y - hexPoint.Y);
if(transform == null)
{
transform = new TranslateTransform();
list.RenderTransform = transform;
}
Duration duration = new Duration(TimeSpan.FromSeconds(0.3));
var xAnimation = CreateDoubleAnimation(transform.X + centerPoint.X - hexPoint.X, duration);
var yAnimation = CreateDoubleAnimation(transform.Y + centerPoint.Y - hexPoint.Y, duration);
transform.BeginAnimation(TranslateTransform.XProperty, xAnimation);
transform.BeginAnimation(TranslateTransform.YProperty, yAnimation);
}