本文整理汇总了C#中System.Windows.DragEventArgs.GetPosition方法的典型用法代码示例。如果您正苦于以下问题:C# DragEventArgs.GetPosition方法的具体用法?C# DragEventArgs.GetPosition怎么用?C# DragEventArgs.GetPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DragEventArgs
的用法示例。
在下文中一共展示了DragEventArgs.GetPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: designPanel_DragOver
void designPanel_DragOver(object sender, DragEventArgs e)
{
try {
IDesignPanel designPanel = (IDesignPanel)sender;
e.Effects = DragDropEffects.Copy;
e.Handled = true;
Point p = e.GetPosition(designPanel);
if (moveLogic == null) {
if (e.Data.GetData(typeof(CreateComponentTool)) != this) return;
// TODO: dropLayer in designPanel
designPanel.IsAdornerLayerHitTestVisible = false;
DesignPanelHitTestResult result = designPanel.HitTest(p, false, true);
if (result.ModelHit != null) {
designPanel.Focus();
DesignItem createdItem = CreateItem(designPanel.Context);
if (AddItemWithDefaultSize(result.ModelHit, createdItem, e.GetPosition(result.ModelHit.View))) {
moveLogic = new MoveLogic(createdItem);
createPoint = p;
} else {
changeGroup.Abort();
}
}
} else if ((moveLogic.ClickedOn.View as FrameworkElement).IsLoaded) {
if (moveLogic.Operation == null) {
moveLogic.Start(createPoint);
} else {
moveLogic.Move(p);
}
}
} catch (Exception x) {
DragDropExceptionHandler.RaiseUnhandledException(x);
}
}
示例2: OnDragOver
protected override void OnDragOver(DragEventArgs e)
{
base.OnDragEnter(e);
HitTestResult result = VisualTreeHelper.HitTest(this, e.GetPosition(this));
if ((result.VisualHit as UIElement).IsDescendantOf(this))
{
UIElement element = (result.VisualHit as UIElement);
DragDropTreeViewItem targetNode = GetNearestContainer(e.Source as UIElement);
if (e.GetPosition(targetNode).Y < targetNode.ActualHeight * 0.2f)
{
// meter em cima
//Console.WriteLine("cima");
DragDropHelper.insertionPlace = DragDropHelper.InsertionPlace.Top;
DragDropHelper.CreateInsertionAdorner(targetNode, true);
}
else if (e.GetPosition(targetNode).Y > targetNode.ActualHeight * 0.8f)
{
//Console.WriteLine("baixo");
DragDropHelper.insertionPlace = DragDropHelper.InsertionPlace.Bottom;
DragDropHelper.CreateInsertionAdorner(targetNode, false);
}
else
{
//Console.WriteLine("centro");
DragDropHelper.RemoveInsertionAdorner();
DragDropHelper.insertionPlace = DragDropHelper.InsertionPlace.Center;
var converter = new System.Windows.Media.BrushConverter();
Background = (Brush)converter.ConvertFromString("#555");
}
}
}
示例3: DropInfo
/// <summary>
/// Initializes a new instance of the DropInfo class.
/// </summary>
/// <param name="sender">
/// The sender of the drag event.
/// </param>
/// <param name="e">
/// The drag event.
/// </param>
/// <param name="dragInfo">
/// Information about the source of the drag, if the drag came from within the framework.
/// </param>
public DropInfo(object sender, DragEventArgs e, DragInfo dragInfo)
{
string dataFormat = DragDrop.DataFormat.Name;
Data = (e.Data.GetDataPresent(dataFormat)) ? e.Data.GetData(dataFormat) : e.Data;
DragInfo = dragInfo;
VisualTarget = sender as UIElement;
if (VisualTarget == null)
return;
DropPosition = e.GetPosition(VisualTarget);
if (!(sender is ItemsControl))
return;
var itemsControl = (ItemsControl)sender;
UIElement item = itemsControl.GetItemContainerAt(DropPosition);
bool directlyOverItem = item != null;
TargetGroup = FindGroup(itemsControl, DropPosition);
VisualTargetOrientation = itemsControl.GetItemsPanelOrientation();
if (item == null)
{
item = itemsControl.GetItemContainerAt(DropPosition, VisualTargetOrientation);
directlyOverItem = false;
}
if (item == null)
{
TargetCollection = itemsControl.ItemsSource ?? itemsControl.Items;
InsertIndex = itemsControl.Items.Count;
return;
}
ItemsControl itemParent = ItemsControl.ItemsControlFromItemContainer(item);
InsertIndex = itemParent.ItemContainerGenerator.IndexFromContainer(item);
TargetCollection = itemParent.ItemsSource ?? itemParent.Items;
if (directlyOverItem)
{
TargetItem = itemParent.ItemContainerGenerator.ItemFromContainer(item);
VisualTargetItem = item;
}
if (VisualTargetOrientation == Orientation.Vertical)
{
if (e.GetPosition(item).Y > item.RenderSize.Height / 2)
InsertIndex++;
}
else
{
if (e.GetPosition(item).X > item.RenderSize.Width / 2)
InsertIndex++;
}
}
示例4: DragScope_PreviewDragOver
void DragScope_PreviewDragOver(object sender, DragEventArgs args)
{
if (this._adorner != null)
{
this._adorner.LeftOffset = args.GetPosition(this._dragScope).X;
this._adorner.TopOffset = args.GetPosition(this._dragScope).Y;
Debug.WriteLine("DragScope_PreviewDragOver:" + _adorner.LeftOffset + "," + _adorner.TopOffset);
}
}
示例5: DropUIElement
public static void DropUIElement(object sender, DragEventArgs e)
{
var mainWin = DesignerMainWindow.GetInstance();
var selectedObj = mainWin.GetSelectedCanvasElement();
var uiElem = selectedObj as UIElement;
InkCanvas.SetLeft(uiElem, e.GetPosition(mainWin.canMainCanvas).X - _elemPos.X);
InkCanvas.SetTop(uiElem, e.GetPosition(mainWin.canMainCanvas).Y - _elemPos.Y);
var selected = new List<UIElement> { uiElem };
mainWin.canMainCanvas.Select(selected);
}
示例6: DropInfo
/// <summary>
/// Constructor.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <param name="dragInfo"></param>
/// <param name="dataFormat"></param>
public DropInfo(object sender, DragEventArgs e, DragInfo dragInfo, string dataFormat)
{
Data = (e.Data.GetDataPresent(dataFormat)) ? e.Data.GetData(dataFormat) : e.Data;
DragInfo = dragInfo;
VisualTarget = sender as UIElement;
if (sender is ItemsControl)
{
ItemsControl itemsControl = (ItemsControl)sender;
Point p = e.GetPosition(itemsControl);
UIElement item = itemsControl.GetItemContainerAt(p);
if (item == null)
{
// try again with margins
p.X -= 15;
p.Y -= 15;
item = itemsControl.GetItemContainerAt(p);
}
VisualTargetOrientation = itemsControl.GetItemsPanelOrientation();
if (item != null)
{
ItemsControl itemParent = ItemsControl.ItemsControlFromItemContainer(item);
InsertIndex = itemParent.ItemContainerGenerator.IndexFromContainer(item);
TargetCollection = itemParent.ItemsSource ?? itemParent.Items;
TargetItem = itemParent.ItemContainerGenerator.ItemFromContainer(item);
VisualTargetItem = item;
if (VisualTargetOrientation == Orientation.Vertical)
{
if (e.GetPosition(item).Y > item.RenderSize.Height / 2) InsertIndex++;
}
else
{
if (e.GetPosition(item).X > item.RenderSize.Width / 2) InsertIndex++;
}
}
else
{
TargetCollection = itemsControl.ItemsSource ?? itemsControl.Items;
InsertIndex = itemsControl.Items.Count;
}
}
this.IsNotHandled = false;
}
示例7: GameObjectsCanvas_Drop
public void GameObjectsCanvas_Drop(object sender, DragEventArgs e)
{
Element element = e.Data.GetData(typeof(Element)) as Element;
if (element != null)
{
System.Console.WriteLine("dropped " + element);
GameObject pGo = App.ObjectBuilder.click(e.GetPosition(sender as Canvas)) as GameObject;
Element newElement = new Element(element);
if (pGo != null)
{
pGo.Add(newElement);
}
else
{
pGo = App.newGameObject();
if (pGo != null)
{
pGo.Position = e.GetPosition(sender as Canvas);
pGo.Add(newElement);
}
}
}
ObjectBuilder ob = e.Data.GetData(typeof(ObjectBuilder)) as ObjectBuilder;
if (ob != null && ob.IsMacro)
{
if (ob.IsRegistered || ob.IsLive)
{
// TODO: Show Macro window
MacroCall macroCall = new MacroCall();
macroCall.Position = e.GetPosition(sender as Canvas);
macroCall.Macro = ob;
if (ob != App.ObjectBuilder)
{
App.ObjectBuilder.ScriptObjects.Add(macroCall);
}
else
{
MessageBox.Show("Cannot call Macro from within itself!", "Error");
}
}
else
{
App.registerMacroInScript(ob);
(App.MainWindow as MainWindow).sortMacros();
}
}
}
示例8: Drop
private static void Drop(object sender, DragEventArgs e)
{
var point = e.GetPosition((IInputElement)sender);
var dropTarget = GetDropTarget((DependencyObject)sender);
dropTarget.Drop(e.Data, point);
e.Handled = true;
}
示例9: MainWindow_PreviewDragOver
void MainWindow_PreviewDragOver(object sender, DragEventArgs e)
{
// Adjust the position of the draggedBlock as it's dragged
if (draggedBlock == null) return;
e.Effects = DragDropEffects.None;
Point p = e.GetPosition(grdMain);
draggedBlock.Margin = new Thickness(p.X - dragPos.X, p.Y - dragPos.Y, 100000, 100000);
}
示例10: GraphDragEventArgs
public GraphDragEventArgs(NodeGraphLayout canvas, DragEventArgs args)
{
Point canvasPoint = args.GetPosition(canvas);
canvasPoint = new Point(canvasPoint.X - canvas.Translation.X, canvasPoint.Y - canvas.Translation.Y);
Position = canvasPoint;
DragArguments = args;
}
示例11: Drawing_Area_Drop
private void Drawing_Area_Drop(object sender, DragEventArgs e)
{
Label label = new Label();
label.Content = e.Data.GetData(DataFormats.Text);
Point labelCord = e.GetPosition(Drawing_Area);
Canvas.SetLeft(label, labelCord.X);
Canvas.SetTop(label, labelCord.Y);
Drawing_Area.Children.Add(label);
}
示例12: OnWidgetDrop
private void OnWidgetDrop(object sender, DragEventArgs e)
{
WidgetDescriptor descriptor = (WidgetDescriptor)e.Data.GetData(WidgetDataFormat);
Point mousePositionInCanvas = e.GetPosition(widgetContainer);
descriptor.Position = mousePositionInCanvas;
descriptor.ZIndex = 100;
descriptor.IsActive = true;
}
示例13: GetPositionFromSender
static Point GetPositionFromSender(object sender, DragEventArgs args)
{
IInputElement inputSender = sender as IInputElement;
if (inputSender != null)
{
return args.GetPosition(inputSender);
}
return new Point();
}
示例14: IsMouseOnStartDot
private bool IsMouseOnStartDot(DragEventArgs e)
{
HitTestResult result = VisualTreeHelper.HitTest(this, e.GetPosition(this));
if (result != null && this.startDotGrid.IsAncestorOf(result.VisualHit))
{
return true;
}
return false;
}
示例15: OnDragEnter
protected override void OnDragEnter(DragEventArgs e)
{
Win32Point wp;
e.Effects = DragDropEffects.Copy;
Point p = e.GetPosition(this);
wp.x = (int)p.X;
wp.y = (int)p.Y;
WindowInteropHelper wndHelper = new WindowInteropHelper(this);
IDropTargetHelper dropHelper = (IDropTargetHelper)new DragDropHelper();
dropHelper.DragEnter(wndHelper.Handle, (ComIDataObject)e.Data, ref wp, (int)e.Effects);
}