本文整理匯總了C#中Windows.UI.Xaml.DragEventArgs.GetPosition方法的典型用法代碼示例。如果您正苦於以下問題:C# DragEventArgs.GetPosition方法的具體用法?C# DragEventArgs.GetPosition怎麽用?C# DragEventArgs.GetPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Windows.UI.Xaml.DragEventArgs
的用法示例。
在下文中一共展示了DragEventArgs.GetPosition方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: WeekGridView_Drop
private async void WeekGridView_Drop(object sender, DragEventArgs e)
{
bool success = false;
StaffItem si = null;
try
{
string itemIndexString = await e.Data.GetView().GetTextAsync("ItemNumber"); //which shift
si = siList.ElementAt(int.Parse(itemIndexString));
success = true;
}
catch
{
//string itemIndexString = await e.Data.GetView().GetTextAsync("ItemNumber2"); //which shift
//StaffItem si = siList2.ElementAt(int.Parse(itemIndexString));
success = false;
}
if (!success)
{
string itemIndexString = await e.Data.GetView().GetTextAsync("ItemNumber2"); //which shift
si = siList2.ElementAt(int.Parse(itemIndexString));
}
////////////////////////////////
//List<StaffItem> temp = (List<StaffItem>)WeekGridView.ItemsSource;
//temp.ElementAt(0).
////////////////////////////////
FrameworkElement root = Window.Current.Content as FrameworkElement;
Point position = this.TransformToVisual(root).TransformPoint(e.GetPosition(this));
int newIndex = 0;
// check items directly under the pointer
foreach (var element in VisualTreeHelper.FindElementsInHostCoordinates(position, root))
{
// assume horizontal orientation
var container = element as ContentControl;
if (container == null)
{
continue;
}
int tempIndex = WeekGridView.IndexFromContainer(container);
if (tempIndex >= 0)
{
newIndex = tempIndex;
// adjust index depending on pointer position
Point center = container.TransformToVisual(root).TransformPoint(new Point(container.ActualWidth / 2, container.ActualHeight / 2));
if (position.Y > center.Y)
{
newIndex++;
}
break;
}
}
if (newIndex < 0)
{
// if we haven't found item under the pointer, check items in the rectangle to the left from the pointer position
foreach (var element in GetIntersectingItems(position, root))
{
// assume horizontal orientation
var container = element as ContentControl;
if (container == null)
{
continue;
}
// int tempIndex = WeekGridView.ItemContainerGenerator.IndexFromContainer(container);
int tempIndex = WeekGridView.IndexFromContainer(container);
if (tempIndex < 0)
{
// we only need GridViewItems belonging to this GridView control
// so skip all elements which are not
continue;
}
Rect bounds = container.TransformToVisual(root).TransformBounds(new Rect(0, 0, container.ActualWidth, container.ActualHeight));
if (bounds.Left <= position.X && bounds.Top <= position.Y && tempIndex > newIndex)
{
//_currentOverGroup = GetItemGroup(container.Content);
newIndex = tempIndex;
// adjust index depending on pointer position
if (position.Y > bounds.Top + container.ActualHeight / 2)
{
newIndex++;
}
if (bounds.Right > position.X && bounds.Bottom > position.Y)
{
break;
}
}
}
}
if (newIndex < 0)
{
newIndex = 0;
}
//.........這裏部分代碼省略.........
示例2: ItemListView2_Drop
private async void ItemListView2_Drop(object sender, DragEventArgs e)
{
string itemIndexString = await e.Data.GetView().GetTextAsync("itemIndex");
var item = storeData.Collection[int.Parse(itemIndexString)];
Point pos = e.GetPosition(ItemListView2.ItemsPanelRoot);
ListViewItem lvi = (ListViewItem)ItemListView2.ContainerFromIndex(0);
double itemHeight = lvi.ActualHeight + lvi.Margin.Top + lvi.Margin.Bottom;
int index = Math.Min(ItemListView2.Items.Count - 1, (int)(pos.Y / itemHeight));
ListViewItem targetItem = (ListViewItem)ItemListView2.ContainerFromIndex(index);
Point positionInItem = e.GetPosition(targetItem);
if (positionInItem.Y > itemHeight / 2)
{
index++;
}
index = Math.Min(ItemListView2.Items.Count, index);
storeData2.Collection.Insert(index, item);
}
示例3: ElementScrollViewer_DragEnter
void ElementScrollViewer_DragEnter(object sender, DragEventArgs e)
{
//}
//private void viewer_MouseMove(object sender, MouseEventArgs e)
//{
if (VerticalOffset == 0 && e != null)
{
//var p = this.TransformToVisual(ElementRelease).Transform(new Point(0, 0));
//if (p.Y < -VerticalPullToRefreshDistance)
double Translation_Y = e.GetPosition(ElementScrollViewer).Y;
if (Translation_Y - ManipulationStartedYOffset < VerticalPullToRefreshDistance)
{
if (!isPulling)
{
isPulling = true;
ChangeVisualState(RefreshState.Pulling, true);
if (EnteredPullRefreshThreshold != null)
{
EnteredPullRefreshThreshold(this, EventArgs.Empty);
}
//GoToState("Pulling", true);
}
}
else if (isPulling)
{
isPulling = false;
if (LeftPullRefreshThreshold != null)
{
LeftPullRefreshThreshold(this, EventArgs.Empty);
}
ChangeVisualState(RefreshState.ReleasePulling, true);
//GoToState("ReleasePulling", true);
}
}
}
示例4: UpdateOutput
async private void UpdateOutput(DragEventArgs e)
{
ClearOutput();
OutputCursorPosition.Text = e.GetPosition(MainGrid).X + "," + e.GetPosition(MainGrid).Y;
string keys = "";
if (e.Modifiers.HasFlag(DragDropModifiers.Alt))
keys += "Alt ";
if (e.Modifiers.HasFlag(DragDropModifiers.Control))
keys += "Control ";
if (e.Modifiers.HasFlag(DragDropModifiers.LeftButton))
keys += "LeftButton ";
if (e.Modifiers.HasFlag(DragDropModifiers.MiddleButton))
keys += "MiddleButton ";
if (e.Modifiers.HasFlag(DragDropModifiers.None))
keys += "None ";
if (e.Modifiers.HasFlag(DragDropModifiers.RightButton))
keys += "RightButton ";
if (e.Modifiers.HasFlag(DragDropModifiers.Shift))
keys += "Shift ";
OutputModifiers.Text = keys;
string acceptedOperations = "";
if (e.AcceptedOperation.HasFlag(DataPackageOperation.Copy))
acceptedOperations += "Copy ";
if (e.AcceptedOperation.HasFlag(DataPackageOperation.Move))
acceptedOperations += "Move ";
if (e.AcceptedOperation.HasFlag(DataPackageOperation.Link))
acceptedOperations += "Link ";
if (e.AcceptedOperation.HasFlag(DataPackageOperation.None))
acceptedOperations += "None ";
OutputAcceptedOperations.Text = acceptedOperations;
string requestedOperations = "";
if (e.DataView.RequestedOperation.HasFlag(DataPackageOperation.Copy))
requestedOperations += "Copy ";
if (e.DataView.RequestedOperation.HasFlag(DataPackageOperation.Move))
requestedOperations += "Move ";
if (e.DataView.RequestedOperation.HasFlag(DataPackageOperation.Link))
requestedOperations += "Link ";
if (e.DataView.RequestedOperation.HasFlag(DataPackageOperation.None))
requestedOperations += "None ";
OutputRequestedOperations.Text = requestedOperations;
if (e.DataView.Contains(StandardDataFormats.ApplicationLink))
OutputDPAppLink.Text = (await e.DataView.GetApplicationLinkAsync()).ToString();
if (e.DataView.Contains(StandardDataFormats.WebLink))
OutputDPWebLink.Text = (await e.DataView.GetWebLinkAsync()).ToString();
if (e.DataView.Contains(StandardDataFormats.Text))
OutputDPText.Text = await e.DataView.GetTextAsync();
if (e.DataView.Contains(StandardDataFormats.Rtf))
OutputDPRtf.Text = await e.DataView.GetRtfAsync();
if (e.DataView.Contains(StandardDataFormats.Html))
OutputDPHTML.Text = await e.DataView.GetHtmlFormatAsync();
if (e.DataView.Contains(StandardDataFormats.Bitmap))
{
BitmapImage image = new BitmapImage();
var streamRef = await e.DataView.GetBitmapAsync();
var stream = await streamRef.OpenReadAsync();
image.SetSource(stream);
OutputDPBitmap.Source = image;
}
if (e.DataView.Contains(StandardDataFormats.StorageItems))
{
var files = await e.DataView.GetStorageItemsAsync();
foreach (var file in files)
{
TextBlock t = new TextBlock();
t.Text = file.Name;
OutputDPFiles.Children.Add(t);
}
}
}
示例5: dropList_DragOver
void dropList_DragOver(object sender, DragEventArgs e)
{
var pos = e.GetPosition(ItemListView2.ItemsPanelRoot);
ListViewItem lvi = (ListViewItem)ItemListView2.ContainerFromIndex(0);
double itemHeight = lvi.ActualHeight + lvi.Margin.Top + lvi.Margin.Bottom;
int index = Math.Min(ItemListView2.Items.Count - 1, (int)(pos.Y / itemHeight));
ListViewItem lvidrop = (ListViewItem)ItemListView2.ContainerFromIndex(index);
if (index != currDropIndex)
{
if (currDropIndex >= 0)
{
//remove the border
ListViewItem lvidropOld = (ListViewItem)ItemListView2.ContainerFromIndex(currDropIndex);
lvidropOld.BorderThickness = noBorder;
}
lvidrop.BorderBrush = blueBorder;
lvidrop.BorderThickness = thickBorder;
currDropIndex = index;
}
}
示例6: ItemListView2_Drop
private async void ItemListView2_Drop(object sender, DragEventArgs e)
{
string data = await e.Data.GetView().GetTextAsync("data");
//Find the position where item will be dropped in the listview
Point pos = e.GetPosition(ItemListView2.ItemsPanelRoot);
//Get the size of one of the list items
ListViewItem lvi = (ListViewItem)ItemListView2.ContainerFromIndex(0);
double itemHeight = lvi.ActualHeight + lvi.Margin.Top + lvi.Margin.Bottom;
//Determine the index of the item from the item position (assumed all items are the same size)
int index = Math.Min(ItemListView2.Items.Count - 1, (int)(pos.Y / itemHeight));
rootPage.NotifyUser("You dropped \'" + data + "\' from the first list onto item \'" + (index + 1) + "\' of the second list", NotifyType.StatusMessage);
//Remove the border from the item
ListViewItem lvidropOld = (ListViewItem)ItemListView2.ContainerFromIndex(currDropIndex);
lvidropOld.BorderThickness = noBorder;
}
示例7: Canvas_Drop
private async void Canvas_Drop(object sender, DragEventArgs e)
{
DataTemplate dataTemplate = this.Resources["PlayerElementTemplate"] as DataTemplate;
var elem = dataTemplate.LoadContent() as FrameworkElement;
var pname = await e.DataView.GetTextAsync();
elem.DataContext = App.MainViewModel.SelectedTeam.Players.First((pl) => pl.Name == pname);
var p = e.GetPosition(Canvas);
Canvas.SetLeft(elem, p.X);
Canvas.SetTop(elem, p.Y);
Canvas.Children.Add(elem);
}